题解 | #xxx定律#
xxx定律
https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8
#include <iostream> //对于一个数n,如果是偶数,那么把n砍掉一半; // 如果是奇数,那么把n变成3n+1后砍掉一半,直到该数变为1为止, // 计算需要经过几步才能将n变为1 int main() { int n; int pace=0; while(scanf("%d",&n)!=EOF){ while(n!=1){ if(n%2==0){ n/=2; pace+=1; } else if(n%2==1){ n=3*n+1; n/=2; pace+=1; } } printf("%d\n",pace); pace=0; } return 0; }