結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kichirb3kichirb3
提出日時 2018-03-03 10:20:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,339 ms / 2,000 ms
コード長 567 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 205,816 KB
最終ジャッジ日時 2023-09-05 23:43:01
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,704 KB
testcase_01 AC 17 ms
7,776 KB
testcase_02 AC 16 ms
7,780 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 AC 15 ms
7,792 KB
testcase_05 AC 16 ms
7,804 KB
testcase_06 AC 16 ms
7,788 KB
testcase_07 AC 15 ms
7,876 KB
testcase_08 AC 18 ms
8,464 KB
testcase_09 AC 36 ms
12,048 KB
testcase_10 AC 209 ms
47,448 KB
testcase_11 AC 1,290 ms
204,156 KB
testcase_12 AC 666 ms
48,512 KB
testcase_13 AC 1,339 ms
205,816 KB
testcase_14 AC 1,220 ms
203,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.526 フィボナッチ数列の第N項をMで割った余りを求める
https://yukicoder.me/problems/no/526
"""
import sys
from sys import stdin
input = stdin.readline


Memo = [-1, 0, 1]
def modfibo(N, M):
    global Memo
    if N <= len(Memo):
        return Memo[N]
    else:
        for i in range(len(Memo), N+1):
            Memo.append((Memo[-2] + Memo[-1])%M)
    return Memo[N]



def main(args):
    N, M = map(int, input().split())
    ans = modfibo(N, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0