結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー _EnumHack_EnumHack
提出日時 2017-06-10 01:17:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 321 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 80,808 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 04:36:41
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
using namespace std;
auto fib_mod(size_t n, size_t m) {
    size_t memo[1000] = {0, 1}, i;
    for (i = 2; i <= n; i++) {
        memo[i] = (memo[i - 1] + memo[i - 2])%m;
    }
    return memo[n];
}

int main(){
    size_t n,m;
    cin >> n >> m;
    cout << fib_mod(n-1,m) << '\n';
}
0