#P8255. [NOI Online 2022 入门组] 数学游戏
[NOI Online 2022 入门组] 数学游戏
Background
After consideration by the administrators, we plan to store the community testdata separately in the last Subtask. These test points are all worth 0 points, but failing any of them will be considered as not passing this problem.
Community testdata provider: @一扶苏一. This problem does not guarantee the strength of the community testdata. For details, see this post.
Problem Description
Kri likes playing number games.
One day, he wrote down pairs of positive integers on scratch paper, and for each pair computed .
But the naughty Zay found Kri's paper, erased every , and may have modified some as well.
Now Kri asks you to help restore each . Specifically, for each given and , you need to output the smallest positive integer such that . If such a does not exist, meaning Zay must have modified , output .
Note: denotes the greatest common divisor of and , i.e. the largest positive integer such that is a divisor of both and .
Input Format
The first line contains one integer , representing that there are pairs of positive integers and .
The next lines each contain two positive integers and , as described above.
Output Format
For each pair, output one line. If there is no positive integer satisfying the condition, output . Otherwise, output the smallest positive integer that satisfies the condition.
1
10 240
12
3
5 30
4 8
11 11
6
-1
1
见附件中的 math3.in
见附件中的 math3.out
见附件中的 math4.in
见附件中的 math4.out
Hint
Sample 1 Explanation
$x \times y \times \gcd(x, y) = 10 \times 12 \times \gcd(10, 12) = 240$.
Constraints
For of the testdata, .
For of the testdata, , , .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5