結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ゆきだまるゆきだまる
提出日時 2021-12-09 23:20:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 10,700 KB
実行使用メモリ 29,672 KB
最終ジャッジ日時 2023-09-24 15:32:17
合計ジャッジ時間 4,987 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,484 KB
testcase_01 AC 133 ms
29,512 KB
testcase_02 AC 131 ms
29,528 KB
testcase_03 AC 138 ms
29,552 KB
testcase_04 AC 138 ms
29,500 KB
testcase_05 AC 137 ms
29,612 KB
testcase_06 AC 135 ms
29,616 KB
testcase_07 AC 133 ms
29,524 KB
testcase_08 AC 130 ms
29,580 KB
testcase_09 AC 139 ms
29,564 KB
testcase_10 AC 133 ms
29,576 KB
testcase_11 AC 130 ms
29,520 KB
testcase_12 AC 132 ms
29,520 KB
testcase_13 AC 134 ms
29,568 KB
testcase_14 AC 132 ms
29,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

def main(n, m):
    #n, m = map(int, input().split())
    x = np.array([[0, 1], [1, 1]])
    y = np.array([[1, 0], [0, 1]])
    s = bin(n)[:1:-1]
    for i in s:
        if i == '1':
            y = np.dot(y, x)
            y %= m
        x = np.dot(x, x)
        x %= m
    z = np.dot(y, [[0], [1]])
    return z[0][0]

n, m = map(int, input().split())
print(main(n-1, m))
0