結果

問題 No.891 隣接3項間の漸化式
ユーザー 👑 rin204
提出日時 2022-03-25 18:07:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 54,016 KB
最終ジャッジ日時 2024-10-14 02:36:34
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
MOD = 10 ** 9 + 7

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C.copy()
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = deepcopy(C)
        w >>= 1
    return B
    
a, b, n = map(int, input().split())
if n == 0:
    print(0)
    exit()
A = [[a, b], [1, 0]]
B = [1, 0]
B = matpow(A, B, n - 1)
print(B[0])
0