标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 53006 | Accepted: 16841 |
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
Source
1 //oimonster 2 #include<cstdio> 3 #include<cstdlib> 4 #include<iostream> 5 using namespace std; 6 int count(int i) 7 { 8 int s=1; 9 while(i!=1) 10 { 11 if(i%2) 12 i=3*i+1; 13 else 14 i/=2; 15 s++; 16 } 17 return s; 18 } 19 int main(){ 20 int i,j,n,max,k,t,ii,jj; 21 while(scanf("%d%d",&i,&j)!=EOF){ 22 ii=i; 23 jj=j; 24 if(i>j){ 25 t=i; 26 i=j; 27 j=t; 28 } 29 max=0; 30 for(n=i;n<=j;n++){ 31 k=count(n); 32 if(k>max)max=k; 33 } 34 printf("%d %d %d\n",ii,jj,max); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/oimonster/p/4289471.html