Greatest of the Greatest Common Divisors
시간 제한1초메모리 제한2048 MB
수열과 q개의 구간 질의가 주어질 때, 각 구간 안에서 서로 다른 두 원소의 최대공약수 가운데 가장 큰 값을 구한다.
문제
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 integers has 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 , and the whole sequence is specified as the interval, the following pairs of two integers at different positions and , and their greatest common divisors should be considered.
The greatest of the greatest common divisors of the pairs is , in this case.
입력
The input consists of a single test case of the following format.
The first line contains an integer n, which is the number of integers in the given sequence, satisfying . The second line contains positive integers through specifying the sequence. None of them exceeds .
The third line contains a positive integer , specifying the number of intervals in the sequence to be considered, which does not exceed . It is followed by lines, each specifying an interval in the sequence to be considered. The -th line of them has two integers, and (), specifying the interval through in the sequence.
출력
Output lines, the -th line of which should have the greatest of the greatest common divisors of all pairs in the interval specified by and .