結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー alorie10
提出日時 2021-06-18 02:09:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 394 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 168,540 KB
実行使用メモリ 276,864 KB
最終ジャッジ日時 2024-06-11 20:21:25
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
ll n,m,mem[5000001];
string s[30];
vector<ll> v;
ll fib(ll a,ll b){
    if(mem[a])return mem[a];
    if(a==1)return 0;
    if(a==2)return 1;
    return mem[a]=(fib(a-1,b)+fib(a-2,b))%b;
}
int main(void){
    cin>>n>>m;
    cout<<fib(n,m)<<endl;
}
0