結果

問題 No.2241 Reach 1
ユーザー lam6er
提出日時 2025-03-31 17:34:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 54,384 KB
最終ジャッジ日時 2025-03-31 17:35:29
合計ジャッジ時間 2,519 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
steps = 0

while n != 1:
    if n % 2 == 0:
        # Divide by the maximum possible power of 2 in one step
        while n % 2 == 0:
            n //= 2
        steps += 1
    else:
        found = False
        # Check up to s=40 which covers 2^40, sufficient for N up to 1e9
        for s in range(1, 40):
            power = (1 << s) - 1  # 2^s - 1
            if power % n == 0:
                steps += 2
                n = 1
                found = True
                break
        if not found:
            # Use k=1 and then divide by 2 until odd
            n += 1
            cnt = 0
            while n % 2 == 0:
                n //= 2
            steps += 2

print(steps)
0