Subtask#1 TLE

B2077 角谷猜想

CSPAK_Zhangxiuqi0011 @ 2023-05-12 18:03:18

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

为啥我开了long long,Subtask#1还是WA


by Neji0907_qwq @ 2023-05-12 18:09:08

@Zhangxiuqi0011

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

by CSPAK_Zhangxiuqi0011 @ 2023-05-12 18:41:46

@Hyuga_Neji 已AC 谢谢 不知为何变成cout就AC了


by chjiyu123456789 @ 2023-07-12 17:00:47

@Zhangxiuqi0011 我和你一样但我改的是变量类型 int改unsigned long long就AC了!


by CSPAK_Zhangxiuqi0011 @ 2023-07-14 18:59:37

@chengjinyuan 有点玄学


|