杭电acm3782

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;
}

 

posted @ 2013-05-08 15:32  执着追求的IT小小鸟  阅读(119)  评论(0编辑  收藏  举报