結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー trineutron
提出日時 2019-07-28 19:28:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 282 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 165,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 15:06:11
合計ジャッジ時間 2,214 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    long n, m;
    cin >> n >> m;
    long prev = 0, current = 1;
    for (long i = 3; i <= n; i++) {
        long w = (current + prev) % m;
        prev = current;
        current = w;
    }
    cout << current << endl;
}
0