結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー square1001square1001
提出日時 2017-08-18 09:51:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 228 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 64,488 KB
実行使用メモリ 42,624 KB
最終ジャッジ日時 2024-04-22 15:42:08
合計ジャッジ時間 1,403 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 19 ms
11,392 KB
testcase_11 AC 88 ms
42,624 KB
testcase_12 AC 87 ms
42,520 KB
testcase_13 AC 87 ms
42,532 KB
testcase_14 AC 84 ms
42,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int N, M; long long dp[5000009];
int main() {
	cin >> N >> M;
	dp[1] = 0; dp[2] = 1;
	for(int i = 3; i <= N; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % M;
	cout << dp[N] << endl;
	return 0;
}
0