結果

問題 No.2534 コラッツ数列
ユーザー srjywrdnprkt
提出日時 2023-07-21 19:48:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 191,392 KB
最終ジャッジ日時 2025-02-15 16:12:33
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    ll cnt=0, step=1, n;
    cin >> n;

    while(1){
        if (cnt > 50){
            cout << "No" << endl;
            return 0;
        }
        if (step == 1){
            cnt++;
            step = 2;
        }
        else if (step == 2){
            cnt++;
            if (n == 1) step = 3;
            else step = 4;
        }
        else if (step == 3) break;
        else{
            cnt++;
            if (n % 2 == 0) n /= 2;
            else n = n * 3 + 1;
            step = 2;
        }
    }

    cout << "Yes" << endl;
    cout << cnt << endl;

    return 0;
}
0