結果

問題 No.891 隣接3項間の漸化式
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-13 18:29:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 637 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,000 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2023-10-20 03:59:39
合計ジャッジ時間 4,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
20,352 KB
testcase_01 AC 30 ms
10,188 KB
testcase_02 AC 31 ms
10,188 KB
testcase_03 AC 30 ms
10,188 KB
testcase_04 AC 30 ms
10,188 KB
testcase_05 AC 29 ms
10,188 KB
testcase_06 AC 29 ms
10,188 KB
testcase_07 AC 33 ms
10,188 KB
testcase_08 AC 28 ms
10,188 KB
testcase_09 AC 30 ms
10,188 KB
testcase_10 AC 31 ms
10,188 KB
testcase_11 AC 30 ms
10,188 KB
testcase_12 AC 29 ms
10,188 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 #

def mat_mul(A, B):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        for k in range(size):
            for j in range(size):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res


def mat_pow(A, n):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res


mod = 10 ** 9 + 7
a, b, n = map(int, input().split())

A = [[a, b], [1, 0]]
A = mat_pow(A, n-1)
print(A[0][0] % mod)
0