結果

問題 No.3631 Collatz conjecture
コンテスト
ユーザー forest3
提出日時 2026-11-02 16:09:27
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 559 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,130 ms
コンパイル使用メモリ 193,164 KB
実行使用メモリ 9,916 KB
最終ジャッジ日時 2026-11-02 16:09:31
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 52 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
using ll = long long;

int main(){
	int n;
	cin >> n;
    if(n == 1) {
        cout << "infinity" << endl;
        return 0;
    }
    set<int> st;
    st.insert(n);
    int k = 0;
    while(n != 1) {
        k++;
        if(n % 2 == 0) {
            n /= 2;
        } else {
            n = 3 * n + 1;
        }
        if(st.count(n)) {
            cout << "infinity" << endl;
            return 0;
        }
        st.insert(n);
    }
    cout << k << endl;
}
0