結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー nbisconbisco
提出日時 2018-04-29 22:04:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 390 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 10,692 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2023-09-10 08:12:02
合計ジャッジ時間 1,304 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,828 KB
testcase_01 AC 16 ms
7,912 KB
testcase_02 AC 16 ms
7,884 KB
testcase_03 AC 16 ms
7,808 KB
testcase_04 AC 15 ms
7,732 KB
testcase_05 AC 15 ms
7,668 KB
testcase_06 AC 16 ms
7,912 KB
testcase_07 AC 16 ms
8,196 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = [int(i) for i in input().strip().split(" ")]

fib_base = [0 % m, 1 % m]
def fib(n):
    if n == 1:
        return fib_base[0]
    elif n == 2:
        return fib_base[1]
    else:
        if len(fib_base) >= n:
            return fib_base[n-1] % m
        else:
            fib_base.append((fib(n-1) % m + fib(n-2) % m) % m)
            return fib_base[-1]
fib(n)
print(fib_base[-1])
0