#include<bits/stdc++.h> using namespace std; int n; int main(){ cin>>n; for(;n>1;){ if (n%2==0){ cout<<n<<"/2="<<n/2<<endl; n/=2; } else{ cout<<n<<"3+1="<<n3+1<<endl; n*=3; n++; } } cout<<"End"; return 0; }

1 comments

  • @ 2025-3-24 10:40:19
    #include<bits/stdc++.h> 
    using namespace std; 
    int n; 
    int main(){ 
    cin>>n;
     for(;n>1;){ 
    if (n%2==0){
     cout<<n<<"/2="<<n/2<<endl;
     n/=2; 
    } 
    else{ 
    cout<<n<<"*3+1="<<n*3+1<<endl; 
    n*=3; 
    n++;
    } 
    }
    cout<<"End"; 
    return 0; 
    }
    

    码风有点丑,将就看吧

    • 1

    Information

    ID
    123
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    27
    Accepted
    12
    Uploaded By