結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ukuku09ukuku09
提出日時 2017-06-09 22:27:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 159,808 KB
実行使用メモリ 42,656 KB
最終ジャッジ日時 2023-10-23 21:40:01
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
6,312 KB
testcase_10 AC 19 ms
12,456 KB
testcase_11 AC 89 ms
42,656 KB
testcase_12 AC 87 ms
42,656 KB
testcase_13 AC 86 ms
42,656 KB
testcase_14 AC 88 ms
42,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int fib[5000050];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  fib[1] = 0, fib[2] = 1;
  reps(i, 3, N+1) fib[i] = (fib[i-1]+fib[i-2])%M;
  cout << fib[N]%M << endl;

  return 0;
}
0