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

GitHub代码(不全,更新中)

分析:水题,不解释

Source Code:

#include <iostream>
using namespace std;

int main()
{
    int n;
    int time = 0;
    cin>>n;

    while(n != 1)
    {
        if(n % 2 == 0)
        {
            n /= 2;
        }
        else
        {
            n = (3 * n + 1) / 2;
        }
        time++;
    }
    cout<<time<<endl;

    return 0;
}
发布了88 篇原创文章 · 获赞 7 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Q_smell/article/details/104130722