結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー RonlynesRonlynes
提出日時 2017-06-09 22:48:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 341 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 55,760 KB
実行使用メモリ 42,736 KB
最終ジャッジ日時 2023-10-23 22:17:28
合計ジャッジ時間 2,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
42,736 KB
testcase_01 AC 29 ms
42,736 KB
testcase_02 AC 28 ms
42,736 KB
testcase_03 AC 28 ms
42,736 KB
testcase_04 AC 28 ms
42,736 KB
testcase_05 AC 29 ms
42,736 KB
testcase_06 AC 28 ms
42,736 KB
testcase_07 AC 28 ms
42,736 KB
testcase_08 AC 28 ms
42,736 KB
testcase_09 AC 30 ms
42,736 KB
testcase_10 AC 45 ms
42,736 KB
testcase_11 AC 112 ms
42,736 KB
testcase_12 AC 112 ms
42,736 KB
testcase_13 AC 112 ms
42,736 KB
testcase_14 AC 111 ms
42,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
long long n, m;
long long fib(long long num) {
	long long dp[5000001]; //計算結果を入れる
	dp[0] = 0;
	dp[1] = 1;
	for (int i = 2; i <= num-1; i++) {
		dp[i] = (dp[i - 1] + dp[i - 2])%m;
	}
	return dp[num-1];
}
int main(void){
    cin >> n >> m;

    cout << fib(n)%m << endl;
    return 0;
}
0