結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー e869120e869120
提出日時 2017-06-09 22:22:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 335 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 77,948 KB
実行使用メモリ 47,328 KB
最終ジャッジ日時 2023-10-23 21:03:48
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
47,328 KB
testcase_01 AC 96 ms
47,328 KB
testcase_02 AC 97 ms
47,328 KB
testcase_03 AC 96 ms
47,328 KB
testcase_04 AC 96 ms
47,328 KB
testcase_05 AC 96 ms
47,328 KB
testcase_06 AC 96 ms
47,328 KB
testcase_07 AC 96 ms
47,328 KB
testcase_08 AC 97 ms
47,328 KB
testcase_09 AC 97 ms
47,328 KB
testcase_10 AC 97 ms
47,328 KB
testcase_11 AC 97 ms
47,328 KB
testcase_12 AC 98 ms
47,328 KB
testcase_13 AC 97 ms
47,328 KB
testcase_14 AC 96 ms
47,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
using namespace std;
long long dp[6000000], n, m;
int main() {
	cin >> n >> m;
	dp[1] = 0; dp[2] = 1;
	for (int i = 3; i < 5500000; i++)dp[i] = (dp[i - 1] + dp[i - 2]) % m;
	cout << dp[n] << endl;
	return 0;
}
0