結果

問題 No.887 Collatz
ユーザー tokutaro
提出日時 2020-03-06 21:43:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 75,752 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 04:58:57
合計ジャッジ時間 1,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n0;
    cin >> n0;
    vector<int> vc;
    vc.push_back(n0);
    int index = 0;
    int before = n0;
    int after = n0;
    while (true) {
        if (after == 1) break;
        if (before % 2 == 0) {
            after = before / 2;
        } else {
            after = 3 * before + 1;
        }
        vc.push_back(after);
        index++;
        before = after;
    }
    cout << index << "\n";
    sort(vc.begin(), vc.end());
    cout << vc.at(vc.size()-1) << "\n";
    return 0;
}
0