結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー alorie10alorie10
提出日時 2020-03-16 18:41:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 340 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 64,916 KB
実行使用メモリ 42,700 KB
最終ジャッジ日時 2023-08-18 19:24:15
合計ジャッジ時間 2,664 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
42,412 KB
testcase_01 AC 89 ms
42,408 KB
testcase_02 AC 87 ms
42,456 KB
testcase_03 AC 88 ms
42,484 KB
testcase_04 AC 86 ms
42,460 KB
testcase_05 AC 88 ms
42,612 KB
testcase_06 AC 87 ms
42,460 KB
testcase_07 AC 85 ms
42,404 KB
testcase_08 AC 86 ms
42,404 KB
testcase_09 AC 84 ms
42,480 KB
testcase_10 AC 86 ms
42,532 KB
testcase_11 AC 87 ms
42,608 KB
testcase_12 AC 86 ms
42,404 KB
testcase_13 AC 88 ms
42,700 KB
testcase_14 AC 87 ms
42,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,bik[5000001];
ll fib(ll n){
    if(n==1)return 0;
    if(n==2)return 1;
    return (fib(n-1)+fib(n-2))%m;
}
int main(void){
    cin>>n>>m;
    bik[1]=0;
    bik[2]=1;
    for(int i=3;i<=5000000;i++){
        bik[i]=(bik[i-1]+bik[i-2])%m;
    }
    cout<<bik[n]<<endl;
}
0