結果

問題 No.891 隣接3項間の漸化式
ユーザー ecotteaecottea
提出日時 2022-10-04 16:40:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,608 KB
実行使用メモリ 29,724 KB
最終ジャッジ日時 2023-08-28 18:24:36
合計ジャッジ時間 10,836 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
29,516 KB
testcase_01 AC 141 ms
29,588 KB
testcase_02 AC 140 ms
29,724 KB
testcase_03 AC 143 ms
29,592 KB
testcase_04 AC 139 ms
29,476 KB
testcase_05 AC 157 ms
29,568 KB
testcase_06 AC 139 ms
29,632 KB
testcase_07 AC 137 ms
29,492 KB
testcase_08 AC 142 ms
29,496 KB
testcase_09 AC 138 ms
29,640 KB
testcase_10 AC 137 ms
29,608 KB
testcase_11 AC 137 ms
29,548 KB
testcase_12 AC 142 ms
29,544 KB
testcase_13 AC 140 ms
29,512 KB
testcase_14 AC 141 ms
29,540 KB
testcase_15 AC 139 ms
29,584 KB
testcase_16 AC 140 ms
29,600 KB
testcase_17 AC 141 ms
29,564 KB
testcase_18 AC 146 ms
29,552 KB
testcase_19 AC 135 ms
29,484 KB
testcase_20 AC 139 ms
29,488 KB
testcase_21 AC 135 ms
29,640 KB
testcase_22 AC 136 ms
29,520 KB
testcase_23 AC 137 ms
29,484 KB
testcase_24 AC 137 ms
29,476 KB
testcase_25 AC 139 ms
29,616 KB
testcase_26 AC 137 ms
29,544 KB
testcase_27 AC 136 ms
29,700 KB
testcase_28 AC 139 ms
29,532 KB
testcase_29 AC 138 ms
29,660 KB
testcase_30 AC 134 ms
29,576 KB
testcase_31 AC 136 ms
29,532 KB
testcase_32 AC 137 ms
29,580 KB
testcase_33 AC 136 ms
29,564 KB
testcase_34 AC 134 ms
29,588 KB
testcase_35 AC 135 ms
29,596 KB
testcase_36 AC 142 ms
29,456 KB
testcase_37 AC 134 ms
29,504 KB
testcase_38 AC 134 ms
29,592 KB
testcase_39 AC 135 ms
29,596 KB
testcase_40 AC 141 ms
29,604 KB
testcase_41 AC 139 ms
29,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

a, b, n = map(int, input().split())

if n <= 1:
    print(n)
    exit()

n -= 1

MOD = 10**9+7

# numpy の内部では多倍長整数を使っているわけではないので注意.
# pow_a = np.array([[a, b], [1, 0]])
# res = np.array([[1, 0], [0, 1]])
# print(res.dtype) -> int32

pow_a = np.array([[a, b], [1, 0]], dtype = 'int64')
res = np.array([[1, 0], [0, 1]], dtype = 'int64')

while n > 0:
    if n % 2 == 1:
        res = np.dot(res, pow_a) % MOD
    pow_a = np.dot(pow_a, pow_a) % MOD
    n //= 2

print(res[0][0])
0