HDU 3782 xxx定律

http://acm.hdu.edu.cn/showproblem.php?pid=3782

View Code
#include <stdio.h>

#include <stdlib.h>



int main()

{

    int n;

    while(scanf("%d",&n),n)

    {

        int cnt=0;

        while(1)

        {

            if(n==1)break;

            if(n&1)

                n=(3*n+1)>>1;

            else

                n>>=1;

            cnt++;

        }

        printf("%d\n",cnt);

    }

    return 0;

}

 

你可能感兴趣的:(HDU)