結果
| 問題 |
No.3045 反復重み付き累積和
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:08:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 819 bytes |
| コンパイル時間 | 252 ms |
| コンパイル使用メモリ | 82,108 KB |
| 実行使用メモリ | 54,556 KB |
| 最終ジャッジ日時 | 2025-03-20 21:09:11 |
| 合計ジャッジ時間 | 3,365 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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