結果

問題 No.891 隣接3項間の漸化式
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-01-03 21:27:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 641 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 82,688 KB
最終ジャッジ日時 2024-04-21 16:30:24
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
57,600 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 41 ms
52,272 KB
testcase_04 AC 41 ms
52,332 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 41 ms
52,352 KB
testcase_07 AC 41 ms
52,352 KB
testcase_08 AC 41 ms
52,736 KB
testcase_09 AC 41 ms
52,352 KB
testcase_10 AC 42 ms
52,424 KB
testcase_11 AC 43 ms
52,480 KB
testcase_12 AC 42 ms
51,968 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
def matrix_multiplication(a, b):
    n = len(a)
    res = [[0] * n for i in range(n)]
    for i in range(n):
        for k in range(n):
            for j in range(n):
                res[i][j] += a[i][k] * b[k][j]
                res[i][j] %= mod
    return res
def matrix_pow(a, k):
    n = len(a)
    res = [[0] * n for i in range(n)]
    for i in range(n):
        res[i][i] = 1
    while k:
        if k & 1:
            res = matrix_multiplication(res, a)
        a = matrix_multiplication(a, a)
        k >>= 1
    return res

a, b, n = map(int, input().split())
M = [[a, b], [1, 0]]
print(matrix_pow(M, n - 1)[0][0])
0