結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ikkunjyanaikaikkunjyanaika
提出日時 2020-08-10 15:59:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 194,852 KB
実行使用メモリ 42,368 KB
最終ジャッジ日時 2024-04-16 19:06:53
合計ジャッジ時間 3,478 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll n,m;
  cin >> n >>m;
 vll f(n+1,0);
 f[2]=1;
 rep(i,3,n+1) f[i]=(f[i-1]+f[i-2])%m; 
  
  cout << f[n] << endl;
}  
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}
0