結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー yuruhiyayuruhiya
提出日時 2019-04-02 20:11:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 307 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 167,056 KB
実行使用メモリ 198,656 KB
最終ジャッジ日時 2024-05-08 01:04:13
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
42,496 KB
testcase_01 AC 29 ms
42,240 KB
testcase_02 AC 29 ms
42,240 KB
testcase_03 AC 29 ms
42,240 KB
testcase_04 AC 29 ms
42,240 KB
testcase_05 AC 30 ms
42,240 KB
testcase_06 AC 30 ms
42,368 KB
testcase_07 AC 29 ms
42,240 KB
testcase_08 AC 28 ms
42,624 KB
testcase_09 AC 31 ms
45,440 KB
testcase_10 AC 71 ms
73,472 KB
testcase_11 AC 232 ms
198,528 KB
testcase_12 AC 254 ms
198,528 KB
testcase_13 AC 240 ms
198,656 KB
testcase_14 AC 240 ms
198,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<long long> fib(5000009);

long long GetFib(int k) {
	if (k == 1)return 0;
	if (k == 2)return 1;
	if (fib[k] != 0)return fib[k];
	return fib[k] = (GetFib(k - 1) + GetFib(k - 2)) % m;
}

int main() {
	cin >> n >> m;
	cout << GetFib(n) << endl;
}
0