結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー fumi6328fumi6328
提出日時 2018-10-09 19:26:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 315 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 165,460 KB
実行使用メモリ 42,368 KB
最終ジャッジ日時 2024-04-20 19:11:37
合計ジャッジ時間 2,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
42,368 KB
testcase_01 AC 13 ms
42,240 KB
testcase_02 AC 14 ms
42,240 KB
testcase_03 AC 12 ms
42,240 KB
testcase_04 AC 13 ms
42,368 KB
testcase_05 AC 13 ms
42,240 KB
testcase_06 AC 13 ms
42,240 KB
testcase_07 AC 12 ms
42,240 KB
testcase_08 AC 13 ms
42,368 KB
testcase_09 AC 15 ms
42,308 KB
testcase_10 AC 28 ms
42,368 KB
testcase_11 AC 92 ms
42,368 KB
testcase_12 AC 92 ms
42,240 KB
testcase_13 AC 91 ms
42,240 KB
testcase_14 AC 92 ms
42,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> f(5000001);
    f[0] = 0,f[1] = 1;
    for(int i = 2; i < n; i++){
        f[i] = f[i-1] + f[i-2];
        f[i] %= m;
    }

    cout << f[n-1] << endl;

    return 0;
}
0