結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
コンテスト
ユーザー tomokinex
提出日時 2017-06-22 11:11:36
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 214 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 337 ms
コンパイル使用メモリ 70,272 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-18 20:16:10
合計ジャッジ時間 1,347 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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:12:11:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:175:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  175 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:6:20: note: 'ans' was declared here
    6 |   long a = 0,b = 1,ans;
      |                    ^~~

ソースコード

diff #
raw source code

#include<iostream>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  long a = 0,b = 1,ans;
  for(int i=0;i<n-2;i++){
    ans = (a+b)%m;
    a = b;
    b = ans;
  }
  cout << ans << endl;
  return 0;
}
0