5 solutions

  • 2
    @ 2024-1-27 11:29:12
    #include<bits/stdc++.h>
    using namespace std;
    int n;
    int main(){
    	cin>>n;
    	while(n!=1){
    		if(n%2){
    			cout<<n<<"*3+1=";
    			n=n*3+1;
    			cout<<n<<endl;
    		}else{
    			cout<<n<<"/2=";
    			n=n/2;
    			cout<<n<<endl;
    		}
    	}
    	cout<<"End"<<endl;
    	return 0;
    }
    
    • 1
      @ 2024-10-1 9:46:02
      #include<iostream>
      using namespace std;
      int main()
      {
          int n;
          cin>>n;
          if(n==1)
          {
              cout<<"End";
              return 0;
          }
          while(n!=1)
          {
              if(n%2==0)
              {
                  cout<<n<<"/2=";
                  n/=2;
                  cout<<n<<endl;
              }
              else
              {
                  cout<<n<<"\*3+1=";
                  n=3*n+1;
                  cout<<n<<endl;
              }
          }
          cout<<"End";
          return 0;
      }
      
      • 0
        @ 2023-9-17 22:23:52
        #include<iostream>
        using namespace std;
        int main(){
        	int jg;
        	cin>>jg;
        	while(jg!=1){
        		if(jg%2==0){
        			cout<<jg<<"/2="<<jg/2<<endl;
        			jg/=2;
        		}else{
        			cout<<jg<<"*3+1="<<jg*3+1<<endl;
        			jg=jg*3+1;
        		}
        	}
        	cout<<"End";
        }
        
        • -1
          @ 2023-9-17 22:23:20
          #include<iostream>using namespace std;int main(){int jg;cin>>jg;while(jg!=1){if(jg%2==0){cout<<jg<<"/2="<<jg/2<<endl;jg/=2;}else{cout<<jg<<"*3+1="<<jg*3+1<<endl;jg=jg*3+1;}}cout<<"End";}
          
          • -2
            @ 2023-8-27 13:30:55
            #include<iostream>
            using namespace std;
            int main(){
            	int jg;
            	cin>>jg;
            	while(jg!=1){
            		if(jg%2==0){
            			cout<<jg<<"/2="<<jg/2<<endl;
            			jg/=2;
            		}else{
            			cout<<jg<<"*3+1="<<jg*3+1<<endl;
            			jg=jg*3+1;
            		}
            	}
            	cout<<"End";
            }
            
            • 1

            Information

            ID
            577
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            1
            Tags
            # Submissions
            35
            Accepted
            27
            Uploaded By