結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー agisagis
提出日時 2017-06-09 22:56:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 503 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 165,664 KB
実行使用メモリ 277,084 KB
最終ジャッジ日時 2023-10-23 23:29:50
合計ジャッジ時間 7,031 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 10 ms
9,116 KB
testcase_10 WA -
testcase_11 AC 424 ms
277,084 KB
testcase_12 AC 419 ms
277,020 KB
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

ll x[5000000] = {};

ll fib(ll n,ll m) {
	if (n == 1) {
		return 0;
	}
	if (n == 2) {
		return 1;
	}
	if (x[n]) {
		return x[n];
	}
	else {
		x[n] = fib(n - 1,m)%m + fib(n - 2,m)%m;
		return x[n];
	}
}

int main() {
	cin.sync_with_stdio(false);
	ll N, M;
	cin >> N >> M;
	cout << fib(N,M) << endl;
	return 0;
}
0