結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー Akisawa3Akisawa3
提出日時 2023-04-22 20:51:35
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 456 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 849,920 KB
最終ジャッジ日時 2024-04-24 23:11:37
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 41 ms
52,096 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 43 ms
51,968 KB
testcase_05 AC 41 ms
52,224 KB
testcase_06 AC 43 ms
52,224 KB
testcase_07 AC 48 ms
58,496 KB
testcase_08 AC 69 ms
74,496 KB
testcase_09 MLE -
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