1001.3n+1猜想

這裏寫圖片描述

#include "stdafx.h"

int count(int n)
{
    static int cnt = 0;
    if (n==1)
    {
        return cnt;
    }
    else if (n%2)
    {
        n = (3 * n + 1)/2;
        ++cnt;
        count(n);
    }
    else
    {
        ++cnt;
        n /= 2;
        count(n);
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    int n;
    cin >> n;
    cout << count(n) << endl;
    return 0;
}
發佈了77 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章