#P11130. 【MX-X5-T2】「GFOI Round 1」Interstellar

【MX-X5-T2】「GFOI Round 1」Interstellar

Background

Original problem link: https://oier.team/problems/X5C.


Interstellar - PIKASONIC

Problem Description

You have a positive integer xx, and you may perform the following operation on it:

  • Choose a positive integer yy, and change xx to gcd(x,y)\gcd(x, y) times itself, i.e., xx×gcd(x,y)x \gets x \times \gcd(x, y).
    (Here, gcd(x,y)\gcd(x, y) denotes the greatest common divisor of xx and yy.)

The initial value of xx is nn. You want to turn it into mm using some number of operations (possibly zero). You want to know the minimum number of operations needed to achieve the goal, or report that it is impossible.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, indicating the number of test cases.

For each test case:

The first line contains two positive integers n,mn, m.

Output Format

For each test case:

  • If it is impossible, i.e., no matter how you operate, xx can never become mm, output 1-1.
  • Otherwise, output a single non-negative integer on one line, representing the minimum number of operations.
6
1 1
2 4
2 6
12 288
30 144000
114 5141919810
0
1
-1
2
3
-1

Hint

Sample Explanation

For the first test case, no operation is needed, so the answer is 00.

For the second test case, you can choose y=6y = 6, then xx becomes 2×gcd(2,6)=42 \times \gcd(2, 6) = 4.

For the third test case, it is easy to prove that no matter what operations you do, you cannot achieve the goal, so output 1-1.

For the fourth test case, you can:

  • Choose y=16y = 16, then xx becomes 12×gcd(12,16)=4812 \times \gcd(12, 16) = 48.
  • Choose y=6y = 6, then xx becomes 48×gcd(48,6)=28848 \times \gcd(48, 6) = 288.

Constraints

Test Point ID nn \le mm \le Score
11 100100 2×1032 \times 10^3 2121
22 101810^{18} 1717
33 10510^5 1414
44 10710^7 1616
55 101810^{18} 3232

For all test cases, 1T2×1051 \le T \le 2 \times 10^5, 1nm10181 \le n \le m \le 10^{18}.

Translated by ChatGPT 5