結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー mitsuomitsuo
提出日時 2017-06-20 11:50:25
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 377 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-10 02:23:43
合計ジャッジ時間 1,076 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 12 ms
6,940 KB
testcase_02 AC 11 ms
6,944 KB
testcase_03 AC 11 ms
6,940 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 10 ms
6,944 KB
testcase_06 AC 11 ms
6,940 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

cache = {1 : 0, 2 : 1}

def fab(k):
    if k < 1:
        return 0
    elif k in cache:
        return cache[k]
    else:
        cache[k] = fab(k - 1) + fab(k - 2)
        return cache[k]

def solve(input):
    n = int(input.split(" ")[0])
    m = int(input.split(" ")[1])
    return fab(n) % m

if __name__ == "__main__":
    print solve(raw_input())
0