結果
| 問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める | 
| コンテスト | |
| ユーザー |  chacoder1 | 
| 提出日時 | 2021-01-31 10:59:36 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 388 ms / 2,000 ms | 
| コード長 | 320 bytes | 
| コンパイル時間 | 2,053 ms | 
| コンパイル使用メモリ | 191,300 KB | 
| 最終ジャッジ日時 | 2025-01-18 10:13:56 | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
#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;
}
            
            
            
        