5 solutions

  • 1
    @ 2023-10-2 16:39:50
    #include<bits/stdc++.h>
    using namespace std;
    int ans;
    void judge(int k)
    {
    
    	if(k==1)
    		cout<<"End";
    	else
    	{
    		if(k%2==0)
    		{
    			ans=k/2;
    			cout<<k<<"/2="<<ans<<endl;
    		}
    		else
    		{
    			ans=k*3+1;
    			cout<<k<<"*3+1="<<ans<<endl;
    		}
    	}
    }
    
    int main()
    {
    	int n;
    	cin>>n;
    	judge(n);
    	while(ans!=1)
    		judge(ans);
    	if(n!=1)
    		cout<<"End";
    	return 0;
    }
    
    • 0
      @ 2024-9-23 17:56:27

      #include<stdio.h> int main(){ long long n,t; scanf("%lld",&n); while(n!=1){ while(n%2==0){ printf("%lld/2=%lld\n",n,n/2); n/=2; } while(n%2!=0&&n!=1){ t=n; n=n3+1; printf("%lld3+1=%lld\n",t,n); } } printf("End"); return 0; }

      • 0
        @ 2024-9-11 21:18:35

        #include <stdio.h>

        int main() { int n, s = 0; scanf("%d", &n); while (1) { if (n % 2!= 0) { s = n * 3 + 1; printf("%d*3+1=%d\n", n, s); } else { s = n / 2; printf("%d/2=%d\n", n, s); } if (s == 1) { break; } n = s; } printf("End"); return 0;

        • 0
          @ 2023-10-27 22:50:27
          #include<iostream>
          using namespace std;
          void Jcgu(int x){
            if(x==1)cout<<"End";
            else if(x%2==0){
              printf("%d/2=%d\n",x,x/2);
              Jcgu(x/2);
            }
            else{
              printf("%d*3+1=%d\n",x,x*3+1);
              Jcgu(x*3+1);
            }
          }
          int main(){
            int n;
            cin>>n;
            Jcgu(n);
            return 0;
          }
          
          • 0
            @ 2023-10-25 15:16:17
            #include<stdio.h>
            #include<math.h>
            #pragma warning(disable:4996) 
            int main()
            {
                int num = 0, temp;;
                scanf("%d", &num);
                while (num != 1)
                {
                    temp = num;
                    if (num % 2 != 0)
                    {
                        num *= 3;
                        num++;
                        printf("%d*3+1=%d\n",  temp ,num);
                    }
                    else
                    {
                        num /= 2;
                        printf("%d/2=%d\n", temp, num);
                    }
                }
                printf("End\n");
                return 0;
            }
            
            • 1

            Information

            ID
            6752
            Time
            1000ms
            Memory
            128MiB
            Difficulty
            7
            Tags
            (None)
            # Submissions
            422
            Accepted
            82
            Uploaded By