GCD requests
You are given an array of non-negative integers of length and queries. Each query consists of two numbers and . For each query, determine the maximum of the greatest common divisors (GCD) of all pairs in the subarray from to . Specifically, find:
Input
The first line contains a single integer () — the size of the array.
The second line contains integers () — the elements of the array.
The third line contains a single integer () — the number of queries.
Each of the next lines contains two integers , () — the boundaries of the query.
Output
For each query, output a single integer — the answer to that query.
Examples
Note
denotes the greatest common divisor of numbers and .
Consider the second example:
In the first four queries, the segment consists of only two numbers, so the answer is their greatest common divisor.
Query : the greatest common divisor is for numbers and , .
Query : calculate .
Query : calculate .
Scoring
( points): ;
( points): ;
( points): ;
( points): all are powers of two;
( points): ;
( points): ;
( points): no additional constraints.