1 solutions

  • 1
    @ 2025-11-8 15:03:56
    #include<bits/stdc++.h>
    using namespace std;
    int get(int x) // k的因数中除k以外最大的因数。
    {
        for(int i=2;i<=sqrt(x);i++)
        {
            if(x%i==0) return x/i;
        }
        return 1;
    }
    int main()
    {
        int q;
        cin>>q;
        while(q--)
        {
            int x,y;
            cin>>x>>y;
            int res=0;
            while(x!=y)
            {
                if(x>y) x=get(x); //x往上走
                else y=get(y); 
                res++;
            }
            cout<<res<<endl;
        }
        return 0;
    }
    
    
    • 1

    Information

    ID
    2814
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    4
    Accepted
    1
    Uploaded By