#CTR0016. gcd
gcd
Description
Given positive integers . Find a positive integer such that:
-
.
-
and .
If it is impossible to find such an integer , output .
Here denotes the greatest common divisor of and , which is the maximum positive integer that divides both and .
Input Format
Each test contains multiple test cases. The first line contains the number of test cases .
The description of the test cases follows.
The first line of each test case contains two positive integers .
Output Format
For each test case:
-
If such an integer doesn't exist, output a single integer .
-
Otherwise, output the integer . If there are multiple answers, output any of them.
Sample Input
5
1 2
2 1
3 6
1000000000000000000 1000000000000000000
172635817456 237896190123
Sample Output
2
-1
2
-1
237896190123
Note
In the first test case, , , let , then , , which satisfies the condition.
In the second test case, it can be proved that no such exists.
In the third test case, , , let , then , , which satisfies the condition.
相关
在下列比赛中: