結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー oooooba
提出日時 2021-03-04 22:24:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 110,244 KB
最終ジャッジ日時 2025-01-19 10:10:47
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <optional>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int64_t n, m;
    cin >> n >> m;
    if (n == 1 || n == 2) {
        cout << n - 1 << endl;
        return 0;
    }
    int64_t x = 0, y = 1;
    for (auto i = 3; i <= n; ++i) {
        auto t = (x + y) % m;
        x = y;
        y = t;
    }
    cout << y << endl;
    return 0;
}
0