标签:des style http color strong os
Description
1. input n 2. print n 3. if n = 1 then STOP 4. if n is odd then n <-- 3n+1 5. else n <-- n/2 6. GOTO 2
Input
Output
Sample Input
1 10 100 200 201 210 900 1000
Sample Output
1 10 20 100 200 125 201 210 89 900 1000 174
#include<iostream> using namespace std; int main() { int x,y,i,j,k,max,a,b; while(scanf("%d%d",&x,&y)!=EOF) { if(x>y) {a=x;b=y;} else {a=y;b=x;} max=-1; for(i=b;i<=a;i++) {k=i;j=1; while(k!=1) { if(k%2==0) k=k/2; else k=3*k+1; j++; } if(j>max) max=j; } cout<<x<<' '<<y<<' '<<max<<endl; } return 0; }
I - The 3n + 1 problem(2.4.2),布布扣,bubuko.com
标签:des style http color strong os
原文地址:http://blog.csdn.net/rememberautumn/article/details/37762091