結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー Akisawa3Akisawa3
提出日時 2023-04-22 22:46:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 461 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 821,244 KB
最終ジャッジ日時 2024-04-25 00:36:16
合計ジャッジ時間 3,625 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 28 ms
10,752 KB
testcase_05 AC 28 ms
10,752 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 29 ms
11,008 KB
testcase_08 AC 41 ms
15,872 KB
testcase_09 AC 788 ms
469,460 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**9)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')

N, M = map(int, input().split())

def fib_memo(n):
    memo = [-1] * (n+1)
    def _fib(n):
        if n == 1:
            return 0
        elif n == 2:
            return 1
        elif memo[n] != -1:
            return memo[n]
        else:
            memo[n] = _fib(n-1) + _fib(n-2)
            return memo[n]
    return _fib(n)

print(fib_memo(N) % M)
0