Problem J: 零起点学算法34——3n+1问题
#include<stdio.h> int main() { int count = 0; int n; scanf("%d",&n); while(n>1) { if(n%2==1) n=n*3+1; else n/=2; count++; } printf("%d\n",count); return 0; }
#include<stdio.h> int main() { int count = 0; int n; scanf("%d",&n); while(n>1) { if(n%2==1) n=n*3+1; else n/=2; count++; } printf("%d\n",count); return 0; }