結果
| 問題 |
No.891 隣接3項間の漸化式
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2020-12-13 18:34:26 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 707 bytes |
| コンパイル時間 | 101 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-09-19 23:45:45 |
| 合計ジャッジ時間 | 2,274 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
def mat_mul(A, B):
size = len(A)
res = [[0] * size for _ in range(size)]
for i in range(size):
for k in range(size):
for j in range(size):
res[i][j] += A[i][k] * B[k][j]
res[i][j] %= mod
return res
def mat_pow(A, n):
size = len(A)
res = [[0] * size for _ in range(size)]
for i in range(size):
res[i][i] = 1
while n:
if n & 1:
res = mat_mul(res, A)
A = mat_mul(A, A)
n >>= 1
return res
mod = 10 ** 9 + 7
a, b, n = map(int, input().split())
if n == 0:
print(0)
exit()
if n == 1:
print(1)
exit()
A = [[a, b], [1, 0]]
A = mat_pow(A, n-1)
print(A[0][0] % mod)
tktk_snsn