求助

B2077 角谷猜想

hyc2013 @ 2024-07-20 13:51:11

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

by 08290177ty @ 2024-07-20 14:16:03

把if改一下,不然会双判

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

int main(){
    long long n;
    cin>>n;
    while(n!=1){
        if(n%2==0){
            cout<<n<<"/2="<<n/2<<endl;
            n/=2;
        }else{
            cout<<n<<"*3+1="<<n*3+1<<endl;
            n=n*3+1;
        }
    }
    cout<<"End";
    return 0;
}

by 08290177ty @ 2024-07-20 14:16:55

@hyc2013 求关(逃


by youyou09 @ 2024-07-20 14:19:37

代码发到私信了,记得看哦!


by hyc2013 @ 2024-07-20 14:24:47

@08290177ty OK了,谢谢大佬


|