結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
コンテスト
ユーザー papannda444
提出日時 2018-11-22 20:32:43
言語 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  
実行時間 -
コード長 357 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 895 ms
コンパイル使用メモリ 173,996 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-30 13:10:23
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'long long int func(long long int)':
main.cpp:13:17: warning: 'temp' may be used uninitialized [-Wmaybe-uninitialized]
   13 |   return temp % m;
      |                 ^
main.cpp:7:33: note: 'temp' was declared here
    7 |   long long num1 = 1, num2 = 1, temp;
      |                                 ^~~~
In function 'long long int func(long long int)',
    inlined from 'int main()' at main.cpp:22:17:
main.cpp:13:17: warning: 'temp' may be used uninitialized [-Wmaybe-uninitialized]
   13 |   return temp % m;
      |                 ^
main.cpp: In function 'int main()':
main.cpp:7:33: note: 'temp' was declared here
    7 |   long long num1 = 1, num2 = 1, temp;
      |                                 ^~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

long long n, m;

long long func(long long a) {
  long long num1 = 1, num2 = 1, temp;
  for(int i = 1; i < a-2; i++) {
    temp = num1 + num2;
    num1 = num2;
    num2 = temp;
  }
  return temp % m;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;

  cout << func(n) << endl;


}
0