結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2018-07-29 15:11:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 29,728 KB
最終ジャッジ日時 2023-09-24 23:21:40
合計ジャッジ時間 6,497 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
29,704 KB
testcase_01 AC 138 ms
29,600 KB
testcase_02 AC 135 ms
29,544 KB
testcase_03 AC 135 ms
29,676 KB
testcase_04 AC 139 ms
29,568 KB
testcase_05 AC 137 ms
29,612 KB
testcase_06 AC 134 ms
29,608 KB
testcase_07 AC 134 ms
29,612 KB
testcase_08 AC 131 ms
29,540 KB
testcase_09 AC 133 ms
29,660 KB
testcase_10 AC 138 ms
29,656 KB
testcase_11 AC 135 ms
29,596 KB
testcase_12 AC 133 ms
29,572 KB
testcase_13 AC 133 ms
29,604 KB
testcase_14 AC 132 ms
29,564 KB
testcase_15 AC 131 ms
29,548 KB
testcase_16 AC 132 ms
29,672 KB
testcase_17 AC 137 ms
29,536 KB
testcase_18 AC 135 ms
29,592 KB
testcase_19 AC 133 ms
29,608 KB
testcase_20 AC 134 ms
29,564 KB
testcase_21 AC 136 ms
29,728 KB
testcase_22 AC 134 ms
29,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


import numpy


M = 1000000007


def mod_mul(a, b, mod=M):
    return numpy.matmul(a, b) % mod


def mod_pow(a, n, mod=M):
    b = numpy.eye(len(a), dtype=a.dtype)
    while n > 0:
        if n % 2 == 1:
            b = mod_mul(a, b, mod)
        a = mod_mul(a, a, mod)
        n //= 2
    return b


def solve(n, mod=M):
    a = numpy.array([[1, 1], [1, 0]], dtype=numpy.int64)
    v = numpy.array([1, 0], dtype=a.dtype)
    res = mod_mul(mod_pow(a, n, mod), v, mod)
    return res[0] * res[1] % mod


def main():
    print(solve(int(input())))


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