結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー al1ce_nanka189ral1ce_nanka189r
提出日時 2017-06-11 23:04:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 903 ms / 2,000 ms
コード長 353 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 11,832 KB
実行使用メモリ 10,208 KB
最終ジャッジ日時 2023-10-24 21:24:52
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,208 KB
testcase_01 AC 29 ms
10,208 KB
testcase_02 AC 30 ms
10,208 KB
testcase_03 AC 28 ms
10,208 KB
testcase_04 AC 27 ms
10,208 KB
testcase_05 AC 27 ms
10,208 KB
testcase_06 AC 26 ms
10,208 KB
testcase_07 AC 26 ms
10,208 KB
testcase_08 AC 27 ms
10,208 KB
testcase_09 AC 37 ms
10,208 KB
testcase_10 AC 123 ms
10,208 KB
testcase_11 AC 791 ms
10,208 KB
testcase_12 AC 395 ms
10,208 KB
testcase_13 AC 903 ms
10,208 KB
testcase_14 AC 714 ms
10,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import math

#-------
# Initialize
N,M = map(int, input().split())

#-------
# Define
def fib(n):
    ans, n1, n2 = 1, 0, 1
    if n == 0: return n1
    if n == 1: return n2
    for i in range(2, n):
        ans = (n1 + n2) % M
        n1 = n2
        n2 = ans
    return ans

#-------
# Do

#-------
# Output
print(fib(N) % M)
0