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

#include<cstdio>
int main()
{
    int num,step=0;
    scanf("%d", &num);
    while (num!=1)
    {
        if (num % 2 == 0) num /= 2;
        else num = (3 * num + 1) / 2;
        step++;
    }
    printf("%d", step);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hebust/p/9498165.html