传统题 1000ms 256MiB

gcd

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

Given positive integers a,ba, b. Find a positive integer xx such that:

  • 1x10181 \leq x \leq 10^{18}.

  • gcd(a,x)=1\gcd(a, x) = 1 and gcd(b,x)>1\gcd(b, x) > 1.

If it is impossible to find such an integer xx, output 1-1.

Here gcd(a,b)\gcd(a, b) denotes the greatest common divisor of aa and bb, which is the maximum positive integer that divides both aa and bb.

Input Format

Each test contains multiple test cases. The first line contains the number of test cases TT .

The description of the test cases follows.

The first line of each test case contains two positive integers a,ba, b .

1T104,1a,b10181 \leq T \leq 10^4,1 \leq a, b \leq 10^{18}

Output Format

For each test case:

  • If such an integer xx doesn't exist, output a single integer 1-1.

  • Otherwise, output the integer xx. 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, a=1a = 1, b=2b = 2, let x=2x = 2, then gcd(a,x)=gcd(1,2)=1gcd(a, x) = gcd(1, 2) = 1, gcd(b,x)=gcd(2,2)=2gcd(b, x) = gcd(2, 2) = 2, which satisfies the condition.

In the second test case, it can be proved that no such xx exists.

In the third test case, a=3a = 3, b=6b = 6, let x=2x = 2, then gcd(a,x)=gcd(3,2)=1gcd(a, x) = gcd(3, 2) = 1, gcd(b,x)=gcd(6,2)=2gcd(b, x) = gcd(6, 2) = 2, which satisfies the condition.

2025XCPC集训队&&算法培训 — 综合训练(一)

未参加
状态
已结束
规则
ACM/ICPC
题目
5
开始于
2025-8-22 19:00
结束于
2025-8-22 22:00
持续时间
3 小时
主持人
参赛人数
21