B1001 害死人不偿命的(3n+1)猜想 (15 分)

一、参考代码:

#include<iostream>
using namespace std;
int main(){
    int n;
    int step = 0;
    cin >> n;
    while(n != 1){
        if(n%2 == 0){
            n /= 2;
        }else{
            n = (n*3 + 1)/2;
        }
        step++;
    }
    cout << step;
    return 0;
}
posted @ 2019-11-07 20:26  睿晞  阅读(106)  评论(0编辑  收藏  举报