結果

問題 No.887 Collatz
ユーザー take000
提出日時 2020-06-24 02:38:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 166,028 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 19:47:10
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    ll a;
    cin >> a;

    int cnt = 0;
    ll ans = a;
    while (1) {
        if (a == 1)
            break;
            
        if (a % 2 == 0)
            a /= 2;
        else
            a = 3 * a + 1;

        ans = max(ans, a);
        cnt++;
    }

    cout << cnt << endl
         << ans << endl;

    return 0;
}
0