結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 488 ms
43,936 KB
testcase_01 AC 494 ms
44,460 KB
testcase_02 AC 491 ms
44,064 KB
testcase_03 AC 498 ms
44,316 KB
testcase_04 AC 499 ms
44,196 KB
testcase_05 AC 504 ms
44,452 KB
testcase_06 AC 492 ms
44,572 KB
testcase_07 AC 497 ms
44,576 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 494 ms
44,068 KB
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def matpow(mat, n, p, mod):
    res = np.identity(n)
    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]])
n, m = map(int, input().split())
print(int(matpow(mat, 2, n, m)[1, 1]))
0