2 solutions

  • 0
    @ 2026-1-21 11:19:53
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        cout<<n<<" ";
        while (n!=1)
        {
            if(n%2==0)n/=2;
            else n=n*3+1;
            cout<<n<<" ";
        }
        return 0;
    }
    
    • 0
      @ 2026-1-17 11:37:57

      水一道题

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

      Information

      ID
      1807
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      5
      Tags
      # Submissions
      18
      Accepted
      14
      Uploaded By