結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー |
|
提出日時 | 2021-03-08 09:49:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 580 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,676 KB |
最終ジャッジ日時 | 2024-10-09 19:03:24 |
合計ジャッジ時間 | 26,411 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 2 |
other | AC * 10 RE * 29 |
ソースコード
import numpy as np A, B, N = map(int, input().split()) MOD = 10 ** 9 + 7 def pow_matrix_mod(x, n, mod=MOD): if not n: return np.eye(len(x), dtype=np.object) if n % 2 == 0: return pow_matrix_mod(x @ x % mod, n // 2) % mod else: return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod if A == 0 and B == 0: ans = 1 if N == 1 else 0 elif A == 0: ans = pow(B, N // 2, MOD) if N % 2 else 0 elif B == 0: ans = pow(A, N - 1, MOD) if N else 0 else: X = np.array([[0, 1], [B, A]]) ans = pow_matrix_mod(X, N)[0, 1] print(ans)