GCD and K-th Query
Time limit1sMemory limit1024 MB
Given a sequence of N positive integers, answer queries for the K-th smallest gcd over all subarrays inside a range [L, R].
- Level
Hard9 of 10
- Topics
- Binary search, Number theory, Divide and conquer
- Solved
- No attempts yet
Problem
A sequence of positive integers of length is given. Write a program that processes the following queries.
- : For every ordered pair with , compute . Sort these values in non-decreasing order and output the -th value.
Here .
For the sequence with and , the possible gcd values are . If , the answer is .
Input
The first line contains the length of the sequence. ()
The second line contains integers separated by spaces. ()
The third line contains the number of queries . ()
From the fourth line, each of the next lines contains one query , , . (, )
Output
For each query, print the result on its own line.