POJ1207-The 3n + 1 problem
http://poj.org/problem?id=1207
注意输入两个数的大小,水。。。
#include <stdio.h> int main(void) { int a,b,m,count,i,max; while(scanf("%d%d",&a,&b)!=EOF) { printf("%d %d ",a,b); if(a>b){m=a;a=b;b=m;} max=0; for(i=a;i<=b;i++) { m=i;count=1; while(m!=1) { if(m%2) m=3*m+1; else m/=2; count++; } if(count>max) max=count; } printf("%d\n",max); } return 0; }