結果

問題 No.887 Collatz
ユーザー はむ吉🐹はむ吉🐹
提出日時 2019-09-20 21:27:48
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 419 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-14 16:19:43
合計ジャッジ時間 2,009 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools


def solve(n0):
    nmax = n0
    n = n0
    if n == 1:
        return 0, 1
    for i in itertools.count(1):
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
        nmax = max(n, nmax)
        if n == 1:
            return i, nmax


def main():
    n0 = int(input())
    imax, nmax = solve(n0)
    print(imax)
    print(nmax)


if __name__ == "__main__":
    main()
0