結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ChipppppChippppp
提出日時 2021-05-18 00:54:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 278 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,348 KB
最終ジャッジ日時 2024-04-16 12:26:59
合計ジャッジ時間 10,854 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 528 ms
44,044 KB
testcase_01 AC 531 ms
43,816 KB
testcase_02 AC 521 ms
43,804 KB
testcase_03 AC 533 ms
43,808 KB
testcase_04 AC 528 ms
44,348 KB
testcase_05 AC 538 ms
43,936 KB
testcase_06 AC 535 ms
43,936 KB
testcase_07 AC 525 ms
44,184 KB
testcase_08 AC 533 ms
43,932 KB
testcase_09 AC 525 ms
43,944 KB
testcase_10 AC 533 ms
44,312 KB
testcase_11 AC 527 ms
43,944 KB
testcase_12 AC 532 ms
43,932 KB
testcase_13 AC 528 ms
43,936 KB
testcase_14 AC 525 ms
43,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n, mod = map(int, input().split())
n -= 1
res = np.array([[1, 0], [0, 1]])
a = np.array([[1, 1], [1, 0]])
while n > 0:
    if n & 1:
        res = np.dot(res, a) % mod
    a = np.dot(a, a) % mod
    n >>= 1
print(np.dot(res, np.array([[1], [0]]))[1][0] % mod)
0