結果

問題 No.891 隣接3項間の漸化式
ユーザー rlangevinrlangevin
提出日時 2023-06-13 23:11:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 71,172 KB
最終ジャッジ日時 2023-09-04 11:19:16
合計ジャッジ時間 6,120 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,624 KB
testcase_01 AC 75 ms
70,744 KB
testcase_02 AC 75 ms
71,100 KB
testcase_03 AC 79 ms
70,624 KB
testcase_04 AC 76 ms
70,752 KB
testcase_05 AC 77 ms
70,688 KB
testcase_06 AC 76 ms
70,628 KB
testcase_07 AC 74 ms
71,004 KB
testcase_08 AC 76 ms
70,692 KB
testcase_09 AC 76 ms
71,172 KB
testcase_10 AC 76 ms
71,160 KB
testcase_11 AC 76 ms
70,744 KB
testcase_12 AC 75 ms
70,628 KB
testcase_13 AC 74 ms
71,072 KB
testcase_14 AC 74 ms
70,708 KB
testcase_15 AC 76 ms
71,160 KB
testcase_16 AC 78 ms
70,632 KB
testcase_17 AC 77 ms
70,636 KB
testcase_18 AC 77 ms
70,692 KB
testcase_19 AC 78 ms
70,652 KB
testcase_20 AC 75 ms
71,160 KB
testcase_21 AC 76 ms
70,844 KB
testcase_22 AC 78 ms
70,904 KB
testcase_23 AC 76 ms
71,056 KB
testcase_24 AC 75 ms
70,748 KB
testcase_25 AC 74 ms
70,744 KB
testcase_26 AC 77 ms
71,160 KB
testcase_27 AC 78 ms
70,880 KB
testcase_28 AC 78 ms
70,620 KB
testcase_29 AC 77 ms
70,624 KB
testcase_30 AC 77 ms
71,096 KB
testcase_31 AC 76 ms
71,108 KB
testcase_32 AC 77 ms
71,160 KB
testcase_33 AC 74 ms
70,912 KB
testcase_34 AC 74 ms
70,760 KB
testcase_35 AC 76 ms
71,068 KB
testcase_36 AC 76 ms
70,620 KB
testcase_37 AC 76 ms
71,072 KB
testcase_38 AC 76 ms
70,456 KB
testcase_39 AC 75 ms
70,632 KB
testcase_40 AC 76 ms
70,492 KB
testcase_41 AC 77 ms
71,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Matprod(A, B, mod):
    N = len(A)
    temp = [[0] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                temp[i][j] += A[i][k] * B[k][j]
                temp[i][j] %= mod
    return temp

def Matpow(A, M, mod):
    N = len(A)
    Mat = [[0] * N for i in range(N)]
    for i in range(N):
        Mat[i][i] = 1
         
    for i in range(64):
        if (M >> i) & 1:
            Mat = Matprod(Mat, A, mod)
        A = Matprod(A, A, mod)
    return Mat     


a, b, n = map(int, input().split())
mod = 10**9 + 7
if n <= 1:
    print(n)
    exit()
    
Mat = [[a, b], [1, 0]]
Mat = Matpow(Mat, n - 1, mod)
print( Mat[0][0] % mod )    
0