http://acm.hdu.edu.cn/showproblem.php?pid=3782
3*n+1问题,直接上代码
View Code
#include<stdio.h> int main() { int a[10001]; int i,x,sum; for(i=1;i<10001;i++) { x=i; sum=0; while(x!=1) { if(x%2==0) x/=2; else x=(3*x+1)/2; sum++; } a[i]=sum; } while(scanf("%d",&x)&&x) printf("%d\n",a[x]); return 0; }