結果

問題 No.891 隣接3項間の漸化式
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-08 01:56:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 615 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 71,516 KB
最終ジャッジ日時 2023-08-19 17:26:47
合計ジャッジ時間 5,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,296 KB
testcase_01 AC 63 ms
71,388 KB
testcase_02 AC 63 ms
71,372 KB
testcase_03 AC 63 ms
71,372 KB
testcase_04 AC 62 ms
71,328 KB
testcase_05 AC 63 ms
71,256 KB
testcase_06 AC 67 ms
71,112 KB
testcase_07 AC 64 ms
71,348 KB
testcase_08 AC 65 ms
71,516 KB
testcase_09 AC 64 ms
71,416 KB
testcase_10 AC 61 ms
71,436 KB
testcase_11 AC 62 ms
71,144 KB
testcase_12 AC 65 ms
71,288 KB
testcase_13 AC 64 ms
71,452 KB
testcase_14 AC 63 ms
71,064 KB
testcase_15 AC 61 ms
71,188 KB
testcase_16 AC 63 ms
71,272 KB
testcase_17 AC 62 ms
71,212 KB
testcase_18 AC 63 ms
71,212 KB
testcase_19 AC 63 ms
71,512 KB
testcase_20 AC 60 ms
71,156 KB
testcase_21 AC 59 ms
70,996 KB
testcase_22 AC 60 ms
71,148 KB
testcase_23 AC 60 ms
71,060 KB
testcase_24 AC 62 ms
71,448 KB
testcase_25 AC 61 ms
71,204 KB
testcase_26 AC 61 ms
71,148 KB
testcase_27 AC 61 ms
71,260 KB
testcase_28 AC 60 ms
71,396 KB
testcase_29 AC 59 ms
71,288 KB
testcase_30 AC 63 ms
71,416 KB
testcase_31 AC 62 ms
71,272 KB
testcase_32 AC 61 ms
71,264 KB
testcase_33 AC 60 ms
71,452 KB
testcase_34 AC 61 ms
71,064 KB
testcase_35 AC 62 ms
71,188 KB
testcase_36 AC 62 ms
71,020 KB
testcase_37 AC 61 ms
71,352 KB
testcase_38 AC 62 ms
71,288 KB
testcase_39 AC 62 ms
71,208 KB
testcase_40 AC 61 ms
71,064 KB
testcase_41 AC 62 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# A*B
def mul(a, b):
    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 pow(a, n):
    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 = mul(a, b)
        a = mul(a, a)
        n = n>>1
    return b

a, b, n = map(int, input().split())
x0 = 0
x1 = 1
A = [[a, b], [1, 0]]
mod = 10**9+7
An = pow(A, n)
xn = An[1][0]*x1+An[1][1]*x0
print(xn%mod)
0