結果
| 問題 | No.3045 反復重み付き累積和 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:08:23 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 819 bytes |
| 記録 | |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 96,108 KB |
| 実行使用メモリ | 79,456 KB |
| 最終ジャッジ日時 | 2026-07-07 12:54:39 |
| 合計ジャッジ時間 | 5,011 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 41 |
ソースコード
def multiply(a, b, mod):
return [
[
(a[0][0] * b[0][0] + a[0][1] * b[1][0]) % mod,
(a[0][0] * b[0][1] + a[0][1] * b[1][1]) % mod
],
[
(a[1][0] * b[0][0] + a[1][1] * b[1][0]) % mod,
(a[1][0] * b[0][1] + a[1][1] * b[1][1]) % mod
]
]
def matrix_power(matrix, power, mod):
result = [[1, 0], [0, 1]] # Identity matrix
while power > 0:
if power % 2 == 1:
result = multiply(result, matrix, mod)
matrix = multiply(matrix, matrix, mod)
power //= 2
return result
def fib(n, mod):
if n == 0:
return 0
base_matrix = [[1, 1], [1, 0]]
result_matrix = matrix_power(base_matrix, n - 1, mod)
return result_matrix[0][0]
n, m = map(int, input().split())
print(fib(n, m) % m)
lam6er