Consider a sequence of N interegs xi. In order to run a number-theoretic statistical experiment,
a random set of queries to this sequence is generated.
Each query is a pair of integers <r, q>. The result of a query will be the Greatest Common Divisor
of the members (GCD) in the subsequence starting with xr and ending with xq.
For example, if sequence (1, 2, 4, 6, 12) is given then for query <1, 5> the result equals
to GCD(1, 2, 4, 6, 12) = 1, for query <2, 4> the result will be GCD(2, 4, 6) = 2,
and for query <4, 5> the result will be GCD(6, 12) = 6.
Your task is to write a program, which will construct a set of results, given a number
sequence (xi) and a set of queries.
Note that the queries may be repeated.
Исходные данные
The first line of the input file contains two integers (N, M) separated by one or several spaces. Number N is
the number of elements in the sequence of numbers. (1<N<=10000). Number M is the number of queries
(0<M<=100000).
The second line contains N integers xi that form the sequence.
The numbers are delimited by one or more spaces (0<xi<=109).
Then M lines follow, containing number pairs (ri, qi) each. The numbers in a pair are
delimited by one or more spaces. A pair is a query for GCD computation of the
members xri ... xqi
(0<ri,qi<=N, ri<qi).
Результат
The first line of the output file must contain the number M. The following M lines must contain the answers.
The i-th line of those M lines must contain the answer to the query <ri, qi>.
Примеры
Исходные данные | Результат |
5 3
1 2 4 6 12
1 5
2 4
4 5
|
3
1
2
6
|
3 3
8 12 15
1 2
2 3
1 3
|
3
4
3
1
|
|