結果

問題 No.891 隣接3項間の漸化式
ユーザー はむ吉🐹はむ吉🐹
提出日時 2019-09-20 22:05:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 29,724 KB
最終ジャッジ日時 2023-10-12 19:17:39
合計ジャッジ時間 8,991 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
29,636 KB
testcase_01 AC 136 ms
29,688 KB
testcase_02 AC 141 ms
29,600 KB
testcase_03 AC 137 ms
29,596 KB
testcase_04 AC 137 ms
29,652 KB
testcase_05 AC 138 ms
29,652 KB
testcase_06 AC 138 ms
29,684 KB
testcase_07 AC 138 ms
29,680 KB
testcase_08 AC 139 ms
29,596 KB
testcase_09 AC 137 ms
29,604 KB
testcase_10 AC 139 ms
29,604 KB
testcase_11 AC 137 ms
29,648 KB
testcase_12 AC 142 ms
29,608 KB
testcase_13 AC 140 ms
29,676 KB
testcase_14 AC 138 ms
29,592 KB
testcase_15 AC 139 ms
29,688 KB
testcase_16 AC 139 ms
29,676 KB
testcase_17 AC 138 ms
29,604 KB
testcase_18 AC 141 ms
29,600 KB
testcase_19 AC 138 ms
29,644 KB
testcase_20 AC 138 ms
29,572 KB
testcase_21 AC 138 ms
29,692 KB
testcase_22 AC 139 ms
29,592 KB
testcase_23 AC 140 ms
29,628 KB
testcase_24 AC 143 ms
29,644 KB
testcase_25 AC 142 ms
29,584 KB
testcase_26 AC 137 ms
29,584 KB
testcase_27 AC 137 ms
29,608 KB
testcase_28 AC 139 ms
29,676 KB
testcase_29 AC 139 ms
29,656 KB
testcase_30 AC 138 ms
29,648 KB
testcase_31 AC 138 ms
29,696 KB
testcase_32 AC 136 ms
29,584 KB
testcase_33 AC 139 ms
29,632 KB
testcase_34 AC 137 ms
29,548 KB
testcase_35 AC 141 ms
29,724 KB
testcase_36 AC 140 ms
29,628 KB
testcase_37 AC 141 ms
29,640 KB
testcase_38 AC 136 ms
29,592 KB
testcase_39 AC 138 ms
29,584 KB
testcase_40 AC 136 ms
29,588 KB
testcase_41 AC 136 ms
29,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import numpy


M = 10 ** 9 + 7


def mat_mul_mod(x, y, mod=M):
    return x @ y % mod


def mat_pow_mod(x, n, mod=M):
    y = numpy.array([[1, 0], [0, 1]], dtype=numpy.int64)
    while n > 0:
        if n % 2 == 1:
            y = mat_mul_mod(y, x, mod)
        x = mat_mul_mod(x, x, mod)
        n >>= 1
    return y


def solve(a, b, n, mod=M):
    x = numpy.array([[a, b], [1, 0]], dtype=numpy.int64)
    res = mat_pow_mod(x, n)
    z = numpy.array([[1, ], [0, ]], dtype=numpy.int64)
    res = mat_mul_mod(res, z, mod)
    return res[1, 0]


def main():
    a, b, n = (int(z) for z in input().split())
    ans = solve(a, b, n)
    print(ans)


if __name__ == "__main__":
    main()
0