#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 tt pairs of positive integers (x,y)(x, y) on scratch paper, and for each pair computed z=x×y×gcd(x,y)z = x \times y \times \gcd(x, y).

But the naughty Zay found Kri's paper, erased every yy, and may have modified some zz as well.

Now Kri asks you to help restore each yy. Specifically, for each given xx and zz, you need to output the smallest positive integer yy such that z=x×y×gcd(x,y)z = x \times y \times \gcd(x, y). If such a yy does not exist, meaning Zay must have modified zz, output 1-1.

Note: gcd(x,y)\gcd(x, y) denotes the greatest common divisor of xx and yy, i.e. the largest positive integer dd such that dd is a divisor of both xx and yy.

Input Format

The first line contains one integer tt, representing that there are tt pairs of positive integers xx and zz.

The next tt lines each contain two positive integers xx and zz, as described above.

Output Format

For each pair, output one line. If there is no positive integer yy satisfying the condition, output 1-1. Otherwise, output the smallest positive integer yy 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 20%20\% of the testdata, t,x,z103t, x, z \le 10^3.

For 40%40\% of the testdata, t103t \le 10^3, x106x \le 10^6, z109z \le 10^9.

For another 30%30\% of the testdata, t104t \le 10^4.

For another 20%20\% of the testdata, x106x \le 10^6.

For 100%100\% of the testdata, 1t5×1051 \le t \le 5 \times 10^5, 1x1091 \le x \le 10^9, 1z<2631 \le z < 2^{63}.

Translated by ChatGPT 5