結果

問題 No.887 Collatz
ユーザー milanis48663220
提出日時 2019-09-20 21:35:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 54,384 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 16:43:33
合計ジャッジ時間 1,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int main(){
    long n;
    cin >> n;
    long a1 = 0, a2 = n;
    if(n == 1) {
        a1 = 1;
        a2 = 1;
        cout << a1 << endl;
        cout << a2 << endl;
        return 0;
    }
    for(int i = 1; i < 400; i++){
        if(n%2 == 0) n /= 2;
        else n = n*3+1;
        if(n == 1) {
            a1 = i;
            break;
        }
        if(n > a2) a2 = n;
       // cout << n << ' ';
    }
    cout << a1 << endl;
    cout << a2 << endl;
}
0