結果
| 問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-03-04 22:22:58 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 595 bytes | 
| コンパイル時間 | 981 ms | 
| コンパイル使用メモリ | 108,652 KB | 
| 最終ジャッジ日時 | 2025-01-19 10:10:41 | 
| ジャッジサーバーID (参考情報) | judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 WA * 2 | 
ソースコード
#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() {
    int32_t n, m;
    cin >> n >> m;
    if (n == 1 || n == 2) {
        cout << n - 1 << endl;
        return 0;
    }
    int32_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;
}
            
            
            
        