結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー yamachasoyamachaso
提出日時 2022-08-03 16:10:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,264 bytes
コンパイル時間 3,597 ms
コンパイル使用メモリ 227,380 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 10:43:16
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 80 ms
4,348 KB
testcase_12 AC 80 ms
4,348 KB
testcase_13 AC 80 ms
4,352 KB
testcase_14 AC 80 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
template<class T> void my_printv(vector<T> v,bool endline = true){
  if(!v.empty()){ for(size_t i{}; i<v.size()-1; i++) cerr<<v[i]<<' '; cerr<<v.back(); }
  if(endline) cerr<<endl;
}
using ll = long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const ll MOD = 1000000007;
// const int MOD = 998244353;

// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;
using mint = modint998244353;
// using mint = modint;

////////////////////////////////////////////////////////////////////////////////////////////
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);


  ll n,m;cin>>n>>m;
  vector<ll> dp(2);
  dp[0] = 0, dp[1] = 1;
  rep(i, n-1) {
    ll t = dp[1];
    dp[1] = (dp[0] + dp[1])%m;
    dp[0] = t;
  }
  cout << dp[0] << endl;
}
0