結果

問題 No.887 Collatz
ユーザー gemygemy
提出日時 2023-11-22 09:22:15
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 433 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 202,240 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-26 07:25:55
合計ジャッジ時間 3,400 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
    // Input
    int n0;
    cin >> n0;

    // Simulate
    vector<int> v = {n0};
    while (v.back() != 1) {
        int n = v.back();
        v.push_back(n & 1 ? 3 * n + 1 : n / 2);
    }

    // Output
    cout << v.size() - 1 << endl;
    cout << *max_element(v.begin(), v.end()) << endl;
}
0