結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー gyu-don
提出日時 2017-07-24 16:20:11
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 341 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 402 ms
コンパイル使用メモリ 74,004 KB
実行使用メモリ 7,856 KB
最終ジャッジ日時 2026-11-04 00:57:30
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/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<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:15:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/ostream.h:204:25: warning: 'fib' may be used uninitialized [-Wmaybe-uninitialized]
  204 |         return _M_insert(static_cast<unsigned long>(__n));
      |                ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function 'int main()':
main.cpp:8:14: note: 'fib' was declared here
    8 |     uint32_t fib;
      |              ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdint>
using namespace std;
int main() {
    uint32_t n, m;
    cin >> n >> m;
    uint32_t prev2 = 0, prev1 = 1;
    uint32_t fib;
    for (uint32_t i = 3; i <= n; i++) {
        fib = prev2 + prev1;
        if (fib > m) fib -= m;
        prev2 = prev1;
        prev1 = fib;
    }
    cout << fib << endl;
}
0