結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
コンテスト
ユーザー tomokinex
提出日時 2017-06-22 11:09:27
言語 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
結果
WA  
実行時間 -
コード長 220 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 490 ms
コンパイル使用メモリ 71,076 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-18 20:16:11
合計ジャッジ時間 1,612 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:13:11: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   13 |   cout << ans << endl;
      |           ^~~
main.cpp:7:7: note: 'ans' was declared here
    7 |   int ans;
      |       ^~~

ソースコード

diff #
raw source code

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