5 solutions
- 1
Information
- ID
- 577
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- # Submissions
- 35
- Accepted
- 27
- Uploaded By
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==1)
{
cout<<"End";
return 0;
}
while(n!=1)
{
if(n%2==0)
{
cout<<n<<"/2=";
n/=2;
cout<<n<<endl;
}
else
{
cout<<n<<"\*3+1=";
n=3*n+1;
cout<<n<<endl;
}
}
cout<<"End";
return 0;
}
#include<iostream>
using namespace std;
int main(){
int jg;
cin>>jg;
while(jg!=1){
if(jg%2==0){
cout<<jg<<"/2="<<jg/2<<endl;
jg/=2;
}else{
cout<<jg<<"*3+1="<<jg*3+1<<endl;
jg=jg*3+1;
}
}
cout<<"End";
}
#include<iostream>using namespace std;int main(){int jg;cin>>jg;while(jg!=1){if(jg%2==0){cout<<jg<<"/2="<<jg/2<<endl;jg/=2;}else{cout<<jg<<"*3+1="<<jg*3+1<<endl;jg=jg*3+1;}}cout<<"End";}
#include<iostream>
using namespace std;
int main(){
int jg;
cin>>jg;
while(jg!=1){
if(jg%2==0){
cout<<jg<<"/2="<<jg/2<<endl;
jg/=2;
}else{
cout<<jg<<"*3+1="<<jg*3+1<<endl;
jg=jg*3+1;
}
}
cout<<"End";
}
By signing up a ZXOJ universal account, you can submit code and join discussions in all online judging services provided by us.