#P1890. gcd 区间

gcd 区间

Problem 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, 1≤n≤1001 \leq n \leq 100, 1≤m≤101 \leq m \leq 10.
  • For 60%60\% of the testdata, 1≤m≤10001 \leq m \leq 1000.
  • For 100%100\% of the testdata, 1≤l≤r≤n≤10001 \leq l \leq r \leq n \leq 1000, 1≤m≤1061 \leq m \leq 10^6, 1≤ai≤1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5