結果

問題 No.891 隣接3項間の漸化式
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-02 11:26:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 53,968 KB
最終ジャッジ日時 2024-04-20 06:04:57
合計ジャッジ時間 2,984 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,312 KB
testcase_01 AC 39 ms
53,344 KB
testcase_02 AC 40 ms
52,208 KB
testcase_03 AC 35 ms
52,880 KB
testcase_04 AC 39 ms
52,768 KB
testcase_05 AC 39 ms
53,184 KB
testcase_06 AC 36 ms
52,324 KB
testcase_07 AC 35 ms
52,884 KB
testcase_08 AC 36 ms
53,840 KB
testcase_09 AC 38 ms
53,088 KB
testcase_10 AC 36 ms
53,552 KB
testcase_11 AC 37 ms
53,536 KB
testcase_12 AC 36 ms
53,248 KB
testcase_13 AC 37 ms
53,968 KB
testcase_14 AC 34 ms
53,352 KB
testcase_15 AC 36 ms
53,748 KB
testcase_16 AC 39 ms
53,476 KB
testcase_17 AC 37 ms
53,084 KB
testcase_18 AC 34 ms
53,228 KB
testcase_19 AC 36 ms
52,804 KB
testcase_20 AC 34 ms
53,192 KB
testcase_21 AC 36 ms
52,888 KB
testcase_22 AC 35 ms
52,944 KB
testcase_23 AC 36 ms
52,912 KB
testcase_24 AC 36 ms
52,500 KB
testcase_25 AC 37 ms
53,060 KB
testcase_26 AC 36 ms
53,680 KB
testcase_27 AC 35 ms
53,112 KB
testcase_28 AC 35 ms
53,224 KB
testcase_29 AC 37 ms
53,008 KB
testcase_30 AC 36 ms
52,264 KB
testcase_31 AC 36 ms
52,820 KB
testcase_32 AC 39 ms
52,536 KB
testcase_33 AC 35 ms
52,636 KB
testcase_34 AC 39 ms
52,940 KB
testcase_35 AC 39 ms
52,524 KB
testcase_36 AC 40 ms
53,288 KB
testcase_37 AC 35 ms
53,556 KB
testcase_38 AC 40 ms
53,832 KB
testcase_39 AC 35 ms
52,480 KB
testcase_40 AC 35 ms
52,320 KB
testcase_41 AC 38 ms
52,392 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]
mod = 10**9+7

if n <= 1:
    print(X[n]%mod)
    exit()

A = [[a, b], [1, 0]]
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