75求助!!!救命!悬赏关注!

B2077 角谷猜想

sanmu_kangping @ 2024-05-28 12:13:42

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

by yedalong @ 2024-05-28 12:18:17

得用while,不能用do-while
@sanmu_kangping


by sanmu_kangping @ 2024-05-28 12:23:05

@yedalong 哦,谢谢


by luogujisuanji @ 2024-05-28 12:31:39

要用while,do while的话必会执行一次


|