結果

問題 No.887 Collatz
ユーザー stone_725
提出日時 2019-12-01 08:40:31
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 334 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 128,424 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 15:41:40
合計ジャッジ時間 1,630 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n, nmax;
    cin >> n;
    nmax = n;
    int i = 0;
    while(n != 1){
        if(n % 2){
            n = 3 * n + 1;
        }else{
            n /= 2;
        }
        nmax = max(nmax, n);
        i++;
    }
    cout << i << "\n" << nmax << "\n";
}
0