Bumblebee's Malfunction
Time limit2sMemory limit1024 MB
For each query segment of an array, output the gcd of the mex values over all nonempty subsets of that segment.
- Level
Easy3 of 10
- Topics
- Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Bumblebee malfunctioned after a fight with the Decepticons. Now he is trying to solve a strange problem. Here is its statement.
Two functions are defined on sets of positive natural numbers. The first is , the smallest positive natural number that does not appear among . The second is , the greatest common divisor of . Bumblebee generated an array of natural numbers and wants to perform the following operation: for given and , enumerate all subsets of the segment of the array from to inclusive, compute the of each non-empty subset, and then compute the of all the resulting values. (It is easy to see that there are of them.)
Bumblebee's computing power is not enough to solve this quickly. Help him.
Input
The first line contains the number (), the length of the array.
The second line contains integers separated by spaces (), the elements of the array.
The third line contains the number (), the number of queries.
Each of the next lines contains two integers and (), the segment for which the function value must be computed.
Output
Print lines. On the -th line, print the answer to the -th query.