#include<iostream>
using namespace std;
int main(){
int n;//n为待测试数字
cin>>n;
int step=0;//初始化步数step为0
while(n!=1){//while循环,条件为n不等于1,n等于1时跳出循环
step++;//while循环开始,步数加1
if(n%2==1){//当n为奇数时
n=(3*n+1)/2;
}
else{//当n为偶数时
n/=2;
}
}
cout<<step;
return 0;
}
胡凡《算法笔记》B1001.害死人不偿命的(3n+1)猜想 C++
最新推荐文章于 2024-07-10 16:47:58 发布