yang1812 @ 2023-11-12 10:49:52
#include<bits/stdc++.h>
using namespace std;
long long n;
int main() {
scanf("%lld",&n);
while(n != 1){
if(n % 2 != 0){
printf("%d*3+1=%d\n",n,n * 3 + 1);
n = n * 3 + 1;
}else{
printf("%d/2=%d\n",n,n / 2);
n = n / 2;
}
}
printf("End");
}
by LgxTpre @ 2023-11-12 10:50:57
@yang1812 你是 longlong 输出为啥 %d
by 2021zjhs005 @ 2023-11-12 10:54:44
@yang1812
把输出的d
改成lld
试试看。
by Xiong_xhrxhr @ 2023-11-29 21:31:09
#include<iostream>
using namespace std;
int main(){
long long n;
cin>>n;
while(n!=1){
if(n%2!=0){
cout<<n<<"*3+1="<<n*3+1<<endl;
n=n*3+1;
}
if(n%2==0){
cout<<n<<"/2="<<n/2<<endl;
n=n/2;
}
}
cout<<"End"<<endl;
return 0;
}
拿去吧,不要钱的