1 solutions

  • 0
    @ 2025-11-5 15:46:10

    C++ :

    #include <cstdlib>
    #include <cstdio>
    using namespace std;
    bool even(long long);
    int main()
    {
    	long long  n;
    	long long c=0;
    	long long k;
    	scanf("%lld",&k);
    	int cc=0;
    	while(k!=1)
    	{
    		if(even(k)==false)
    		{
    			long long  a=3*k+1;
    			cc++;
    			if(cc==1)
    			{
    				printf("%d",k);
    			}
    			else
    			{
    				printf("-->%d",k);
    			}
                k=a;
                
    		}
    		else
    		{
    			long long a=k/2;
    			cc++;
    			if(cc==1)
    			{
    				printf("%d",k);
    			}
    			else
    			{
    				printf("-->%d",k);
    			}
    			k=a;
    		}
    	}
    	printf("-->1\n%d",cc);
    	//system("pause");
    	return 0;
    }
    bool even(long long a)
    {
    	if(a%2==0)
    	    return true;
    	else
    		return false;
    }
    
    
    • 1

    Information

    ID
    17147
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By