結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー keisuke6keisuke6
提出日時 2022-07-12 17:17:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 262 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 243,128 KB
実行使用メモリ 49,932 KB
最終ジャッジ日時 2023-09-05 19:47:54
合計ジャッジ時間 5,507 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
49,920 KB
testcase_01 AC 108 ms
49,820 KB
testcase_02 AC 108 ms
49,824 KB
testcase_03 AC 109 ms
49,880 KB
testcase_04 AC 108 ms
49,928 KB
testcase_05 AC 108 ms
49,780 KB
testcase_06 AC 108 ms
49,856 KB
testcase_07 AC 108 ms
49,820 KB
testcase_08 AC 109 ms
49,932 KB
testcase_09 AC 109 ms
49,780 KB
testcase_10 AC 109 ms
49,868 KB
testcase_11 AC 108 ms
49,784 KB
testcase_12 AC 110 ms
49,852 KB
testcase_13 AC 108 ms
49,856 KB
testcase_14 AC 108 ms
49,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,M;
  cin>>N>>M;
  vector<int> S(6000000);
  S[0] = 0;
  S[1] = 1;
  for(int i=2;i<S.size();i++){
      S[i] = S[i-1]+S[i-2];
      S[i] %= M;
  } 
  cout<<S[N-1]<<endl;
}
0