結果

問題 No.2363 k-bonacci
ユーザー lam6er
提出日時 2025-03-20 20:39:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 60,180 KB
最終ジャッジ日時 2025-03-20 20:39:48
合計ジャッジ時間 2,999 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

if N == 0:
    print(-1)
else:
    max_k = (N.bit_length() - 1) + 2
    max_k = max(max_k, 2)
    found = False

    for k in range(2, max_k + 1):
        # Initial window is [0]*(k-1) + [1]
        window = [0] * (k - 1) + [1]
        sum_so_far = 1  # Sum of the current window

        if N == 1:
            print(k)
            found = True
            break

        while True:
            next_term = sum_so_far
            if next_term > N:
                break
            if next_term == N:
                print(k)
                found = True
                break
            # Update window and sum for the next term calculation
            popped = window.pop(0)
            sum_so_far -= popped
            window.append(next_term)
            sum_so_far += next_term

        if found:
            break

    if not found:
        print(-1)
0