結果

問題 No.891 隣接3項間の漸化式
ユーザー convexineqconvexineq
提出日時 2019-09-20 22:25:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,016 KB
最終ジャッジ日時 2023-10-12 19:53:24
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,760 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 15 ms
7,756 KB
testcase_14 WA -
testcase_15 AC 16 ms
7,756 KB
testcase_16 AC 15 ms
7,804 KB
testcase_17 AC 16 ms
7,872 KB
testcase_18 WA -
testcase_19 AC 16 ms
7,828 KB
testcase_20 AC 16 ms
7,824 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 15 ms
7,840 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 15 ms
7,760 KB
testcase_38 WA -
testcase_39 AC 15 ms
7,760 KB
testcase_40 WA -
testcase_41 AC 16 ms
7,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD=10**9+7

def matmul(A,B,mod): # A,B: 行列
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= mod
    return res

def matpow(A,p,M): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1,M), M)
    elif p > 0:
        b = matpow(A,p//2,M)
        return matmul(b,b,M)
    else:
        return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]


a,b,n = [int(i) for i in input().split()]
A = [[0,b],[1,a]]

ans = matpow(A,n,MOD)
print(ans[0][1])
0