結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー |
![]() |
提出日時 | 2019-09-28 13:18:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-10-02 00:43:38 |
合計ジャッジ時間 | 2,993 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
a, b, n = [ int(v) for v in input().split() ]path_mat = [ [a, b], [1, 0] ]mod = 10**9+7def mat_mul(inmat1,inmat2,m):outmat = [ [ 0 for j in range(m) ] for i in range(m) ]for i in range(m):for j in range(m):for g in range(m):outmat[i][j] += inmat1[i][g] * inmat2[g][j]outmat[i][j] %= modreturn outmatans_mat = [ [ 1 if i == j else 0 for j in range(2) ] for i in range(2) ]while n != 0:if n % 2 == 1:ans_mat = mat_mul(ans_mat,path_mat,2)n = n // 2path_mat = mat_mul(path_mat,path_mat,2)print(ans_mat[1][0])