結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 13 ms
7,536 KB
testcase_11 WA -
testcase_12 AC 56 ms
23,036 KB
testcase_13 WA -
testcase_14 AC 53 ms
23,000 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 (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int N, M;
int 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;
  }
  int ans = a[N] % M;
  cout << ans << endl;
  return 0;
}
0