以下の内容はhttps://blog.hamayanhamayan.com/entry/2019/09/21/102515より取得しました。


Collatz [yukicoder 887]

https://yukicoder.me/problems/no/887

解説

https://yukicoder.me/submissions/382000

制約を見てみると、シミュレートできそうな雰囲気がある。
400回までが上限なので、ぶん回す。

int n0;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> n0;

    int i1 = -1, nmax = n0;
    int n = n0;
    rep(i, 0, 400)
    {
        if (n == 1 and i1 < 0) {
            i1 = i;
            break;
        }

        chmax(nmax, n);

        if (n % 2 == 0)
            n = n / 2;
        else
            n = 3 * n + 1;
    }
    cout << i1 << endl;
    cout << nmax << endl;
}



以上の内容はhttps://blog.hamayanhamayan.com/entry/2019/09/21/102515より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14