結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー alorie10alorie10
提出日時 2021-06-18 02:09:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 394 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 164,700 KB
実行使用メモリ 198,772 KB
最終ジャッジ日時 2023-09-02 13:43:01
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 7 ms
7,272 KB
testcase_10 AC 57 ms
42,424 KB
testcase_11 AC 277 ms
198,756 KB
testcase_12 AC 294 ms
198,732 KB
testcase_13 AC 272 ms
198,648 KB
testcase_14 AC 272 ms
198,772 KB
権限があれば一括ダウンロードができます

ソースコード

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