1 solutions

  • 0
    @ 2024-11-1 17:41:32
    #include<bits/stdc++.h>
    using namespace std;
    long long n,a[10005],cnt;
    int main(){
        cin>>n;
        while(n!=1){
            a[cnt++]=n;
            if(n%2==0){
                n/=2;
            }
            else{
                n=n*3+1;
            }
    
        } 
        a[cnt]=1;
        for(int i=cnt;i>=0;i--){
            cout<<a[i]<<" ";
        }
        return 0;
    }
    

    Information

    ID
    397
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    76
    Accepted
    41
    Uploaded By