結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー bellangeldindonbellangeldindon
提出日時 2019-05-10 11:34:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 875 ms / 2,000 ms
コード長 229 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 6,664 KB
実行使用メモリ 164,732 KB
最終ジャッジ日時 2023-09-14 17:52:37
合計ジャッジ時間 4,835 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,996 KB
testcase_01 AC 12 ms
5,868 KB
testcase_02 AC 12 ms
5,964 KB
testcase_03 AC 12 ms
6,132 KB
testcase_04 AC 11 ms
5,944 KB
testcase_05 AC 11 ms
5,940 KB
testcase_06 AC 11 ms
5,964 KB
testcase_07 AC 11 ms
5,824 KB
testcase_08 AC 13 ms
6,228 KB
testcase_09 AC 29 ms
8,924 KB
testcase_10 AC 177 ms
37,368 KB
testcase_11 AC 848 ms
164,724 KB
testcase_12 AC 875 ms
164,680 KB
testcase_13 AC 843 ms
164,728 KB
testcase_14 AC 846 ms
164,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def fib(n, m):
	if n == 1: return 0
	if n == 2: return 1
	memo = [0, 1]
	for i in range(3, n+1):
		tmp = (memo[0]+memo[1])%m
		memo[0] = memo[1]
		memo[1] = tmp
	return memo[1]
N, M = map(int, raw_input().split())
print fib(N, M)
0