結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー H3PO4H3PO4
提出日時 2023-07-31 08:44:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,340 KB
最終ジャッジ日時 2024-04-18 09:13:18
合計ジャッジ時間 13,291 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 501 ms
44,056 KB
testcase_01 AC 504 ms
43,956 KB
testcase_02 AC 505 ms
44,328 KB
testcase_03 AC 506 ms
43,960 KB
testcase_04 AC 502 ms
44,208 KB
testcase_05 AC 505 ms
43,952 KB
testcase_06 AC 502 ms
43,952 KB
testcase_07 AC 507 ms
43,956 KB
testcase_08 AC 509 ms
44,208 KB
testcase_09 AC 508 ms
43,952 KB
testcase_10 AC 504 ms
44,200 KB
testcase_11 AC 504 ms
43,952 KB
testcase_12 AC 506 ms
44,340 KB
testcase_13 AC 506 ms
43,956 KB
testcase_14 AC 504 ms
44,336 KB
testcase_15 AC 502 ms
44,200 KB
testcase_16 AC 504 ms
44,076 KB
testcase_17 AC 503 ms
43,940 KB
testcase_18 AC 504 ms
44,056 KB
testcase_19 AC 507 ms
44,332 KB
testcase_20 AC 502 ms
44,340 KB
testcase_21 AC 506 ms
43,960 KB
testcase_22 AC 509 ms
44,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 1_000_000_007


def pow_matrix_mod(x, n, mod=MOD):
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


N = int(input())
A = np.array([[1, 1], [1, 0]], dtype=object)
res = pow_matrix_mod(A, N)
print(res[0, 0] * res[0, 1] % MOD)
0