还是觉得代码放这靠谱,会定期的看看和优化代码
#include <stdio.h> #include <stdlib.h> int main() { int n; int count=0; scanf("%d",&n); if(n<=0 || n>1000)exit(0); else { while(n!=1) { if(n%2==0) { n=n/2; count++; } else { n=(3*n+1)/2; count++; } } } printf("%d\n",count); return 0; }
时间: 2024-10-10 00:34:53