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

来源:互联网 发布:jsp引入java文件 编辑:程序博客网 时间:2024/06/03 19:03

题目链接


题解:

最基本的输入输出,不值得浪费时间。

本题特意用位运算代替了除以2的运算。


代码:

#include <iostream> using namespace std;int main(){int n, cnt = 0;cin >> n;while(n > 1){if(n % 2 == 0)n >>= 1;elsen = (3 * n + 1) >> 1;cnt++;}cout << cnt;return 0;}


原创粉丝点击