結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー nerungonerungo
提出日時 2022-08-25 13:00:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 164,608 KB
実行使用メモリ 42,368 KB
最終ジャッジ日時 2024-04-20 22:00:55
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 18 ms
11,008 KB
testcase_11 AC 86 ms
42,368 KB
testcase_12 AC 101 ms
42,240 KB
testcase_13 AC 100 ms
42,240 KB
testcase_14 AC 101 ms
42,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n+1); i++)
#define all(x) (x).begin(), (x).end()

//using mint = modint1000000007;
//using mint = modint998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const int INF = 1<<30;
const long long INFL = (ll)1<<60;
const double PI = 3.14159265358979;

int main() {
  int n, m;
  cin >> n >> m;
  vl f(n);
  f[0] = 0;
  f[1] = 1;
  for(int i=2;i<n;i++){
    f[i] = f[i-1] + f[i-2];
    f[i] %= m;
  }
  cout << f[n-1] << endl;
  return 0;
}
0