結果

問題 No.891 隣接3項間の漸化式
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-02 11:23:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 721 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 53,832 KB
最終ジャッジ日時 2024-04-20 06:03:01
合計ジャッジ時間 3,137 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# A*B
def mat_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 mat_pow(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 == 1:
            B = mat_mul(A, B, mod)
        A = mat_mul(A, A, mod)
        n = n>>1
    return B

# https://yukicoder.me/problems/no/891
a, b, n = map(int, input().split())
X = [0, 1]
A = [[a, b], [1, 0]]
mod = 10**9+7
A = mat_pow(A, n-1, mod)
ans = 0
for i in range(2):
    ans += A[0][i]*X[1-i]
print(ans%mod)
0