結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー toma_tanichaeltoma_tanichael
提出日時 2020-08-23 09:20:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 161,896 KB
実行使用メモリ 42,644 KB
最終ジャッジ日時 2024-04-23 17:29:34
合計ジャッジ時間 2,525 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 19 ms
11,640 KB
testcase_11 AC 89 ms
42,644 KB
testcase_12 AC 89 ms
42,480 KB
testcase_13 AC 89 ms
42,496 KB
testcase_14 AC 90 ms
42,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

long long N, M;
long long a[5000001];


int main() {
  cin >> N >> M;
  a[1] = 0;
  a[2] = 1;
  rep(i, N) {
    a[i+3] = a[i+2] + a[i+1];
    a[i+3] %= M;
  }
  long long ans = a[N] % M;
  cout << ans << endl;
  return 0;
}
0