結果

問題 No.891 隣接3項間の漸化式
ユーザー neterukunneterukun
提出日時 2019-09-20 22:32:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 75,964 KB
最終ジャッジ日時 2023-10-12 20:05:43
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,436 KB
testcase_01 AC 72 ms
71,324 KB
testcase_02 AC 71 ms
71,356 KB
testcase_03 AC 73 ms
71,272 KB
testcase_04 AC 72 ms
71,044 KB
testcase_05 AC 72 ms
71,204 KB
testcase_06 AC 77 ms
75,636 KB
testcase_07 AC 77 ms
71,040 KB
testcase_08 AC 76 ms
71,288 KB
testcase_09 AC 75 ms
71,328 KB
testcase_10 AC 75 ms
71,432 KB
testcase_11 AC 75 ms
71,276 KB
testcase_12 AC 73 ms
71,304 KB
testcase_13 AC 72 ms
71,360 KB
testcase_14 AC 73 ms
71,048 KB
testcase_15 AC 75 ms
71,464 KB
testcase_16 AC 75 ms
71,404 KB
testcase_17 AC 74 ms
71,288 KB
testcase_18 AC 75 ms
71,264 KB
testcase_19 AC 75 ms
71,412 KB
testcase_20 AC 73 ms
71,036 KB
testcase_21 AC 72 ms
71,268 KB
testcase_22 AC 74 ms
71,456 KB
testcase_23 AC 75 ms
71,328 KB
testcase_24 AC 73 ms
71,304 KB
testcase_25 AC 79 ms
75,728 KB
testcase_26 AC 79 ms
75,620 KB
testcase_27 AC 79 ms
75,572 KB
testcase_28 AC 79 ms
75,632 KB
testcase_29 AC 78 ms
75,628 KB
testcase_30 AC 76 ms
75,620 KB
testcase_31 AC 79 ms
75,964 KB
testcase_32 AC 77 ms
75,712 KB
testcase_33 AC 78 ms
75,720 KB
testcase_34 AC 78 ms
75,616 KB
testcase_35 AC 77 ms
75,636 KB
testcase_36 AC 77 ms
75,688 KB
testcase_37 AC 79 ms
75,736 KB
testcase_38 AC 78 ms
75,792 KB
testcase_39 AC 77 ms
75,728 KB
testcase_40 AC 79 ms
75,668 KB
testcase_41 AC 79 ms
75,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def _mul(A, B, MOD):
    C = [[0] * len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for k in range(len(B)):
            for j in range(len(B[0])):
                C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % MOD
    return C

#A**n
def pow_matrix(A, n, MOD):
    B = [[0] * len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1:
            B = _mul(A, B, MOD)
        A = _mul(A, A, MOD)
        n  = n // 2
    return B

a, b, n = map(int, input().split())
MOD = 10**9 + 7
x0 = 0
x1 = 1
x2 = a*x1 + b*x0
matrix = [[a, b, 0], [1, 0, 0], [0, 1, 0]]

ans_matrix = pow_matrix(matrix, n, MOD)
ans = ans_matrix[2][0]*x2 + ans_matrix[2][1]*x1 + ans_matrix[2][2]*x0 
print(ans % MOD)
0