PAT B1001 害死人不偿命的(3n+1)猜想 (15)

AC代码

#include <cstdio>

int main()
{
    int n,step;
    scanf("%d", &n);
    while(n != 1)
    {
        if(n % 2 == 0) n = n / 2;
        else n = (3 * n + 1) / 2;
        step++;
    }
    printf("%d\n", step);

    return 0;
}
posted @ 2019-08-03 21:58  哨音  阅读(144)  评论(0编辑  收藏  举报