結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー zundamo-tizundamo-ti
提出日時 2020-10-23 12:08:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 422 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,716 KB
実行使用メモリ 33,980 KB
最終ジャッジ日時 2023-09-28 15:19:36
合計ジャッジ時間 7,904 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
33,980 KB
testcase_01 AC 138 ms
29,500 KB
testcase_02 AC 139 ms
29,432 KB
testcase_03 AC 140 ms
29,536 KB
testcase_04 AC 140 ms
29,492 KB
testcase_05 AC 146 ms
29,564 KB
testcase_06 AC 136 ms
29,504 KB
testcase_07 AC 145 ms
29,468 KB
testcase_08 AC 223 ms
29,500 KB
testcase_09 AC 857 ms
29,624 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, M = map(int, input().split())
F = np.array([[1, 1], [1, 0]])

def modpow(F, n):
    if n == 0:
        return np.array([[1, 0], [0, 1]])
    if n % 2 == 0:
        ret = modpow(F, n // 2) @ modpow(F, n // 2)
        ret %= M
        return ret
    else:
        ret = F @ modpow(F, n // 2) @ modpow(F, n // 2)
        ret %= M
        return ret

X = modpow(F, N - 1) @ np.array([1, 0])
print(X[1])
0