1 条题解

  • 0
    @ 2025-10-2 14:44:05
    #include <bits/stdc++.h>
    using namespace std;
    void work()
    {
        long long n, m;
        cin >> n >> m;
        if (m % n != 0)
        {
            cout << "-1\n";
            return;
        }
        int ans = 0;
        while (n != m)
        {
            long long k = m / n;
            long long d = __gcd(n, k);
            if (d == 1)
            {
                cout << "-1\n";
                return;
            }
            n = n * d;
            ans++;
        }
        cout << ans << "\n";
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int T;
        cin >> T;
        while (T--)
            work();
        return 0;
    }
    
    • 1

    信息

    ID
    106
    时间
    2000ms
    内存
    512MiB
    难度
    7
    标签
    递交数
    46
    已通过
    10
    上传者