2 solutions

  • 0
    @ 2026-4-15 16:55:27
    #include<iostream>
    using namespace std;
    int main(){
        int T;
        cin>>T;
        while(T--){
            long long n;
            cin>>n;
            int cnt2=0,cnt3=0,cnt5=0;
            while(n%2==0){
                cnt2++;
                n/=2;
            }
            while(n%3==0){
                cnt3++;
                n/=3;
            }
            while(n%5==0){
                cnt5++;
                n/=5;
            }
            if(n!=1){
                cout<<-1<<endl;
                continue;
            }
            int steps=0;
            steps+=cnt5;
            cnt2+=2*cnt5;
            steps+=cnt3;
            cnt2+=cnt3;
            steps+=cnt2;
            cout<<steps<<endl;
        }
        return 0;
    }

    Information

    ID
    1610
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    (None)
    # Submissions
    85
    Accepted
    37
    Uploaded By