#P1890. gcd 区间

gcd 区间

Description

Given nn positive integers a1,a2,,ana_1, a_2, \dots, a_n.

There are mm queries. For each query, given an interval [l,r][l, r], output the greatest common divisor of al,al+1,,ara_l, a_{l+1}, \dots, a_r.

Input Format

The first line contains two integers n,mn, m.
The second line contains nn integers representing a1,a2,,ana_1, a_2, \dots, a_n.
Each of the next mm lines contains two integers l,rl, r representing the left and right endpoints of the query interval.

Output Format

Print mm lines, each line is the answer to one query.

5 3
4 12 3 6 7
1 3
2 3
5 5

1
3
7

Hint

  • For 30%30\% of the testdata, 1n1001 \leq n \leq 100, 1m101 \leq m \leq 10.
  • For 60%60\% of the testdata, 1m10001 \leq m \leq 1000.
  • For 100%100\% of the testdata, 1lrn10001 \leq l \leq r \leq n \leq 1000, 1m1061 \leq m \leq 10^6, 1ai1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5