結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー hir355hir355
提出日時 2020-02-19 22:57:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 365 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,312 KB
最終ジャッジ日時 2024-04-17 06:10:35
合計ジャッジ時間 8,817 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 505 ms
44,312 KB
testcase_01 AC 492 ms
43,804 KB
testcase_02 AC 495 ms
44,048 KB
testcase_03 AC 491 ms
43,800 KB
testcase_04 AC 496 ms
43,928 KB
testcase_05 AC 493 ms
44,304 KB
testcase_06 AC 499 ms
43,804 KB
testcase_07 AC 488 ms
44,192 KB
testcase_08 AC 498 ms
43,796 KB
testcase_09 AC 498 ms
44,184 KB
testcase_10 AC 509 ms
44,200 KB
testcase_11 AC 559 ms
44,068 KB
testcase_12 AC 488 ms
44,052 KB
testcase_13 AC 495 ms
44,060 KB
testcase_14 AC 498 ms
44,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def matpow(mat, n, p, mod):
    res = np.identity(n).astype('q')
    while p > 0:
        if p & 1:
            res = res @ mat
            res %= mod
        mat = mat @ mat
        mat %= mod
        p >>= 1
    return res


mat = np.array([[1, 1], [1, 0]]).astype('q')
n, m = map(int, input().split())
print(int(matpow(mat, 2, n, m)[1, 1]))
0