結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー chacoder1chacoder1
提出日時 2021-01-31 10:59:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 320 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 196,744 KB
実行使用メモリ 198,840 KB
最終ジャッジ日時 2023-09-11 05:55:42
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,508 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 7 ms
7,240 KB
testcase_10 AC 59 ms
42,420 KB
testcase_11 AC 272 ms
198,668 KB
testcase_12 AC 296 ms
198,644 KB
testcase_13 AC 270 ms
198,840 KB
testcase_14 AC 270 ms
198,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
ll n,m;
ll res[5000010];

ll fiv(ll x,ll y){
  if(res[x] != 0) return res[x];
  if(x==1) return 0;
  if(x==2) return 1;
  res[x]=(fiv(x-1,y)+fiv(x-2,y))%y;
  return res[x];
}

int main(){
  ll n,m;
  cin>>n>>m;
  cout<<fiv(n,m)<<endl;
  return 0;
}


0