結果

問題 No.891 隣接3項間の漸化式
ユーザー Konton7
提出日時 2019-09-28 13:06:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 54,180 KB
最終ジャッジ日時 2024-10-02 00:19:07
合計ジャッジ時間 3,285 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 10 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b, n = [ int(v) for v in input().split() ]

path_mat = [ [a, b], [1, 0] ]

mod = 10**9+7

def 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] %= mod
    return outmat


ans_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 // 2
    path_mat = mat_mul(path_mat,path_mat,2)
    
print(ans_mat[0][1]%mod)
0