結果
| 問題 | No.2363 k-bonacci |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:39:24 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 877 bytes |
| 記録 | |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 96,108 KB |
| 実行使用メモリ | 83,736 KB |
| 最終ジャッジ日時 | 2026-07-07 11:46:52 |
| 合計ジャッジ時間 | 5,026 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
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)
lam6er