liuyi0905 @ 2023-01-22 19:00:15
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
if(a==1)cout<<"End";
while(a!=1){
if(a%2==1){
cout<<a<<"*3+1="<<a*3+1;
a=a*3+1;
}
else{
cout<<a<<"/2="<<a/2;
a/=2;
}
if(a==1)cout<<"End";
}
return 0;
}
求助
by ZQIN_P @ 2023-01-22 19:02:47
@liuyi0905 您输出的换行呢?
by ZQIN_P @ 2023-01-22 19:07:39
@liuyi0905 还有您超时的原因是没有开long long
, 导致输入成为负数陷入近乎死循环, 将int a
改为long long a
即可
by liuyi0905 @ 2023-01-22 20:10:06
by A_Learning_Hornet @ 2023-01-23 14:17:56
@liuyi0905 我前面Subtask1也TLE的,用了long long,AC了!!!