| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 101 | 35 | 31 | 36.905% |
You are given a sequence of integers and a number of intervals in the sequence. The intervals are specified by their leftmost and rightmost positions. An interval consisting of $k$ integers has $k(k - 1)/2$ pairs of integers at different positions, which have their greatest common divisors. For each given interval, find the greatest one among such greatest common divisors.
For example, when the sequence is $(a_1, \dots , a_6) = (10, 20, 30, 40, 50, 60),ドル and the whole sequence is specified as the interval, the following 15ドル$ pairs of two integers at different positions $x$ and $y,ドル and their greatest common divisors should be considered.
| $x$ | 1ドル$ | 1ドル$ | 1ドル$ | 1ドル$ | 1ドル$ | 2ドル$ | 2ドル$ | 2ドル$ | 2ドル$ | 3ドル$ | 3ドル$ | 3ドル$ | 4ドル$ | 4ドル$ | 5ドル$ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| $y$ | 2ドル$ | 3ドル$ | 4ドル$ | 5ドル$ | 6ドル$ | 3ドル$ | 4ドル$ | 5ドル$ | 6ドル$ | 4ドル$ | 5ドル$ | 6ドル$ | 5ドル$ | 6ドル$ | 6ドル$ |
| $a_x$ | 10ドル$ | 10ドル$ | 10ドル$ | 10ドル$ | 10ドル$ | 20ドル$ | 20ドル$ | 20ドル$ | 20ドル$ | 30ドル$ | 30ドル$ | 30ドル$ | 40ドル$ | 40ドル$ | 50ドル$ |
| $a_y$ | 20ドル$ | 30ドル$ | 40ドル$ | 50ドル$ | 60ドル$ | 30ドル$ | 40ドル$ | 50ドル$ | 60ドル$ | 40ドル$ | 50ドル$ | 60ドル$ | 50ドル$ | 60ドル$ | 60ドル$ |
| $\gcd(a_x,a_y)$ | 10ドル$ | 10ドル$ | 10ドル$ | 10ドル$ | 10ドル$ | 10ドル$ | 20ドル$ | 10ドル$ | 20ドル$ | 10ドル$ | 10ドル$ | 30ドル$ | 10ドル$ | 20ドル$ | 10ドル$ |
The greatest of the greatest common divisors of the 15ドル$ pairs is $\gcd(30, 60) = 30,ドル in this case.
The input consists of a single test case of the following format.
$n$
$a_1$ $\cdots$ $a_n$
$q$
$l_1$ $r_1$
$\vdots$
$l_q$ $r_q$
The first line contains an integer n, which is the number of integers in the given sequence, satisfying 2ドル ≤ n ≤ 10^5$. The second line contains $n$ positive integers $a_1$ through $a_n$ specifying the sequence. None of them exceeds 10ドル^5$.
The third line contains a positive integer $q,ドル specifying the number of intervals in the sequence to be considered, which does not exceed 10ドル^5$. It is followed by $q$ lines, each specifying an interval in the sequence to be considered. The $i$-th line of them has two integers, $l_i$ and $r_i$ (1ドル ≤ l_i < r_i ≤ n$), specifying the interval $a_{l_i}$ through $a_{r_i}$ in the sequence.
Output $q$ lines, the $i$-th line of which should have the greatest of the greatest common divisors of all pairs in the interval specified by $l_i$ and $r_i$.
6 10 20 30 40 50 60 3 1 6 2 5 4 5
30 20 10
10 13 2 35 4 13 2 5 1 7 4 5 1 4 4 10 3 8 3 9 1 10
2 4 5 7 13