题解 | 魔法数字变换
魔法数字变换
https://www.nowcoder.com/practice/db41a6ce80a646aa9a5eb6252ac2df76
#include<math.h>
#include<stdio.h>
int main()
{
int x = 0;
int count = 0;
scanf("%d", &x);
while (x!=1)
{
if (x % 2 == 0)//ou
{
x /= 2;
count++;
}
else //ji
{
x = x * 3 + 1;
count++;
}
}
printf("%d\n", count);
}
