結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー tokutaro
提出日時 2020-03-21 17:28:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 69,376 KB
実行使用メモリ 68,944 KB
最終ジャッジ日時 2024-12-23 04:46:53
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 2; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> vc;
    vc.push_back(0);
    vc.push_back(1);
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }
    REP(i, N) {
        vc.push_back((vc.at(i - 2) + vc.at(i - 1)) % M);
    }
    cout << vc.at(N - 1) << endl;
    return 0;
}
0