75求助

B2077 角谷猜想

liuhaowei123 @ 2025-01-11 09:58:50

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

by wangshengchen @ 2025-01-11 10:28:33

@liuhaowei123 这样就对了。

#include<iostream>
using namespace std;
int main()
{
    long long a,b=0;
    cin>>a;
    while(a>1)
    {
        if(a%2==0)
        {
            cout<<a<<"/2="<<a/2<<"\n";
            a/=2;
        }
        else
        {   
            if(a==1){/**********************************/
                cout<<"End";
                return 0;
            }
            cout<<a<<"*3+1="<<a*3+1<<"\n";
            a=a*3+1;
        }
    }
    cout<<"End";
    return 0;
}

by wangshengchen @ 2025-01-11 10:28:58

@liuhaowei123

求关


by XIE_HAO @ 2025-01-11 10:31:16

#include<bits/stdc++.h>
using namespace std;

long long n; //不开long long见祖宗

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

by liuhaowei123 @ 2025-01-11 10:57:46

已关注


|