結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー まぬるねこまぬるねこ
提出日時 2021-06-02 23:03:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 555 ms / 2,000 ms
コード長 366 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,568 KB
最終ジャッジ日時 2024-04-27 15:29:28
合計ジャッジ時間 11,044 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 527 ms
44,060 KB
testcase_01 AC 520 ms
44,060 KB
testcase_02 AC 517 ms
44,564 KB
testcase_03 AC 535 ms
44,568 KB
testcase_04 AC 541 ms
44,060 KB
testcase_05 AC 547 ms
44,312 KB
testcase_06 AC 520 ms
44,052 KB
testcase_07 AC 521 ms
44,440 KB
testcase_08 AC 523 ms
44,056 KB
testcase_09 AC 528 ms
44,436 KB
testcase_10 AC 526 ms
44,308 KB
testcase_11 AC 516 ms
44,068 KB
testcase_12 AC 521 ms
44,440 KB
testcase_13 AC 536 ms
44,308 KB
testcase_14 AC 555 ms
44,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

def powmodmat(n,pow,mod):
    val = np.identity(n.shape[0], dtype=int)
    while pow > 0:
        if pow & 1:
            val = np.dot(val, n) % mod
        pow = pow >> 1
        n = np.dot(n, n) % mod
    return val

n, m = map(int, input().split())

a = np.array([[1, 1], [1, 0]])
a = powmodmat(a,n-2,m)
ans = a[0][0]

print("{}".format(ans))
0