啊~~~75分!为什么!!!

B2077 角谷猜想

_cheems_ckr_ @ 2023-06-08 21:41:26

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

by _cheems_ckr_ @ 2023-06-08 21:42:21

到底是那里错了???样例过了啊


by Qiubit @ 2023-06-08 21:46:16

@DadCelL

printf("%d")

改成

printf("%lld")

by smart_ @ 2023-06-08 22:14:13

@DadCelL 应为:

#include<iostream>
using namespace std;
int main()
{
    int a,s=0;
    cin>>a;
    while(a!=1)
    {
        if(a%2==1)
        {
            cout<<a<<" ";
            a=a*3+1;
            s++;
        } 
        if(a%2==0)
        { 
            a=a/2;
        }
        if(a==1) break;
    }
    if(s==0)
    {
        cout<<"No number can be output!";
    }
    return 0;
} 

by smart_ @ 2023-06-08 22:14:52

我用的是cin,cout


by songyouyi @ 2023-06-11 10:05:25

113383的话会爆int


by tu_huang_di @ 2023-06-18 20:19:55

@DadCelL

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

by liyifan0804 @ 2023-07-18 11:34:48

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a;
    cin>>n;
    //n=1的时候好像要单独处理
    if(n==1){
        cout<<"End";
    }
    while(n>1){
        if(n%2==0){
            a=n/2;
            cout<<n<<"/2="<<a<<endl;
            n=a;
        }else{
            a=n*3+1;
            cout<<n<<"*3+1="<<a<<endl;
            n=a;
        }
        if(a==1){
            cout<<"End";
        }
    }
    return 0;
}

by liyifan0804 @ 2023-07-18 11:35:12

@DadCelL


|