题解 | #魔法数字变换#
魔法数字变换
http://www.nowcoder.com/practice/db41a6ce80a646aa9a5eb6252ac2df76
啊这,我本以为还会很难,但没想到就这:
#include<stdio.h>
int main()
{
int n = 0;
int count = 0;
scanf("%d",&n);
while(n != 1)
{
if(n%2 ==1)
{
n=3*n+1;
count++;
}
else
{
n=n/2;
count++;
}
}
printf("%d\n",count);
return 0;
}