题解 | xxx定律
#include <stdio.h> int main() { int n,i=0; while(scanf("%d",&n)!=EOF){ if(n==1){ i=0; printf("%d\n",i); break; } while(n!=1){ if(n%2==0) n/=2; else n=(3*n+1)/2; i++; } printf("%d\n",i); } return 0; }
#include <stdio.h> int main() { int n,i=0; while(scanf("%d",&n)!=EOF){ if(n==1){ i=0; printf("%d\n",i); break; } while(n!=1){ if(n%2==0) n/=2; else n=(3*n+1)/2; i++; } printf("%d\n",i); } return 0; }
相关推荐