結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー koseki2580koseki2580
提出日時 2023-01-11 19:52:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 423 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 29,632 KB
最終ジャッジ日時 2023-08-24 01:26:51
合計ジャッジ時間 4,892 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
29,436 KB
testcase_01 AC 125 ms
29,460 KB
testcase_02 AC 124 ms
29,452 KB
testcase_03 AC 122 ms
29,564 KB
testcase_04 AC 124 ms
29,616 KB
testcase_05 AC 125 ms
29,472 KB
testcase_06 AC 130 ms
29,500 KB
testcase_07 AC 127 ms
29,540 KB
testcase_08 AC 127 ms
29,436 KB
testcase_09 AC 125 ms
29,520 KB
testcase_10 AC 125 ms
29,380 KB
testcase_11 AC 125 ms
29,632 KB
testcase_12 AC 128 ms
29,540 KB
testcase_13 AC 124 ms
29,380 KB
testcase_14 AC 122 ms
29,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
N, M = map(int, input().split())


def calc(n, m):
    n -= 1
    a = np.array([1, 1, 1, 0]).reshape(2, 2)
    ans = np.array([1, 0, 0, 1]).reshape(2, 2)
    while n != 0:
        if n & 1 == 1:
            ans = np.dot(ans, a)
            ans %= m
        n >>= 1
        a = np.dot(a, a)
        a %= m
    ans = np.dot(ans, np.array([1, 0]).reshape(2, 1))
    return ans[1][0] % m


print(calc(N, M))
0