题目链接->link
思路
- 依题意判断奇偶累计即可。
代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
int n,count=0;
scanf("%d",&n);
while(n!=1){
if(n%2==0){
n/=2;
count++;
}
else {
n=(3*n+1)/2;
count++;
}
}
printf("%d\n",count);
return 0;
}