Range GCD
Time limit2sMemory limit512 MB
Support range add and range GCD queries on an array by tracking a difference array with a segment tree and one prefix sum.
- Level
Hard8 of 10
- Topics
- Segment tree, Number theory, Math
- Solved
- No attempts yet
Problem
You are given a sequence of natural numbers . Two kinds of operations act on this sequence.
- Add the same value to every element of a contiguous range.
- Compute the greatest common divisor of the elements in a contiguous range.
Process the operations in the order they are given, and print an answer for every operation of the second kind.
Input
The first line contains the number of elements . ()
The second line contains the elements of the sequence, separated by spaces. The -th number is , and .
The third line contains the number of operations . ()
Each of the next lines contains one operation as three integers , , .
- If is not 0, add to every element from the -th through the -th.
- If is 0, print the greatest common divisor of the elements from the -th through the -th.
satisfies , and and satisfy . At least one operation has equal to 0.
Output
For every operation with equal to 0, print the greatest common divisor of the requested range on its own line, in the order the operations are given.