eolymp
bolt
Try our new interface for solving problems
Problems

Modified GCD

Modified GCD

Find the greatest common divisor $d$ between two integers $a$ and $b$ that is in a given range from $low$ to $high$ (inclusive), i.e. $low \le d \le high$. It is possible that there is no common divisor in the given range. You will be given the two integers $a$ and $b$, then $n$ queries. Each query is a range from $low$ to $high$ and you have to answer each query. \InputFile The first line contains two integers $a$ and $b~(1 \le a, b \le 10^9)$. The second line contains the number of queries $n~(1 \le n \le 10^4)$. Then $n$ lines follow, each line contains one query consisting of two integers $low$ and $high~(1 \le low \le high \le 10^9)$. \OutputFile Print $n$ lines. The $i$-th of them should contain the result of the $i$-th query. If there is no common divisor in the given range for the query, print $-1$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
9 27
3
1 5
10 11
9 11
Output example #1
3
-1
9