結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
コンテスト
ユーザー f843nmfwisfeuw
提出日時 2020-09-14 20:24:50
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 532 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 466 ms
コンパイル使用メモリ 107,540 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-06 05:25:39
合計ジャッジ時間 1,159 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:33:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:175:25: warning: 'F3' may be used uninitialized [-Wmaybe-uninitialized]
  175 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:26:10: note: 'F3' was declared here
   26 |     long F3;
      |          ^~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

int main() {


    long N, M;
    cin >> N >> M;

    long F1 = 0;
    long F2 = 1;
    long F3;
    for (int i = 3; i <= N; ++i) {
        F3 = ((F2 % M) + (F1 % M)) % M;
        F1 = F2;
        F2 = F3;
    }

    cout << F3 << endl;

    return 0;

}
0