結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー toyontoyon
提出日時 2020-05-05 14:24:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 422 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 163,276 KB
実行使用メモリ 11,272 KB
最終ジャッジ日時 2023-09-08 15:53:26
合計ジャッジ時間 3,739 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 20 ms
11,272 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;
ll N, M;
ll dp[1000010];

int main() {
    cin >> N >> M;
    dp[0] = 0;
    dp[1] = 1;

    for (int i = 2; i <= N - 1; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
        dp[i] %= M;
    }
    cout << dp[N - 1] << endl;
}
0