結果

問題 No.891 隣接3項間の漸化式
ユーザー roarisroaris
提出日時 2019-09-20 22:02:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 71,564 KB
最終ジャッジ日時 2023-10-12 19:10:09
合計ジャッジ時間 6,698 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,268 KB
testcase_01 AC 75 ms
71,064 KB
testcase_02 AC 76 ms
71,304 KB
testcase_03 AC 75 ms
71,288 KB
testcase_04 AC 76 ms
71,196 KB
testcase_05 AC 76 ms
71,064 KB
testcase_06 AC 74 ms
71,256 KB
testcase_07 AC 76 ms
71,440 KB
testcase_08 AC 75 ms
71,068 KB
testcase_09 AC 75 ms
71,468 KB
testcase_10 AC 75 ms
71,164 KB
testcase_11 AC 76 ms
71,196 KB
testcase_12 AC 75 ms
71,064 KB
testcase_13 AC 77 ms
71,184 KB
testcase_14 AC 74 ms
71,300 KB
testcase_15 AC 76 ms
71,068 KB
testcase_16 AC 76 ms
71,368 KB
testcase_17 AC 75 ms
71,064 KB
testcase_18 AC 77 ms
71,296 KB
testcase_19 AC 74 ms
71,260 KB
testcase_20 AC 76 ms
71,272 KB
testcase_21 AC 77 ms
71,264 KB
testcase_22 AC 77 ms
71,060 KB
testcase_23 AC 78 ms
71,200 KB
testcase_24 AC 77 ms
71,564 KB
testcase_25 AC 76 ms
71,224 KB
testcase_26 AC 77 ms
71,284 KB
testcase_27 AC 76 ms
71,268 KB
testcase_28 AC 79 ms
71,416 KB
testcase_29 AC 78 ms
71,184 KB
testcase_30 AC 77 ms
71,356 KB
testcase_31 AC 76 ms
71,468 KB
testcase_32 AC 78 ms
71,348 KB
testcase_33 AC 78 ms
71,420 KB
testcase_34 AC 76 ms
71,048 KB
testcase_35 AC 79 ms
71,304 KB
testcase_36 AC 78 ms
71,296 KB
testcase_37 AC 79 ms
71,068 KB
testcase_38 AC 79 ms
71,280 KB
testcase_39 AC 78 ms
71,464 KB
testcase_40 AC 77 ms
71,288 KB
testcase_41 AC 76 ms
71,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_mul(A, B):
    C = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(B)):
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD
    
    return C
 
def mat_pow(A, n):
    res = [[0 for _ in range(len(A))] for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n > 0:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    
    return res

a, b, n = map(int, input().split())
MOD = 10**9 + 7
A = [[a, b], [1, 0]]
A = mat_pow(A, n)
print(A[1][0])
0