Logo
(追記) (追記ここまで)

33007번 - Greatest of the Greatest Common Divisors 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB101353136.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$.

제한

예제 입력 1

6
10 20 30 40 50 60
3
1 6
2 5
4 5

예제 출력 1

30
20
10

예제 입력 2

10
13 2 35 4 13 2 5 1 7 4
5
1 4
4 10
3 8
3 9
1 10

예제 출력 2

2
4
5
7
13

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > 2024 ICPC Asia Yokohama Regional Contest I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /