結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
![]() |
提出日時 | 2017-06-09 22:54:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 507 bytes |
コンパイル時間 | 1,468 ms |
コンパイル使用メモリ | 165,264 KB |
実行使用メモリ | 276,864 KB |
最終ジャッジ日時 | 2024-09-22 16:30:38 |
合計ジャッジ時間 | 3,276 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 8 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++) ll x[5000000] = {}; ll fib(ll n) { if (n == 1) { return 0; } if (n == 2) { return 1; } if (x[n]) { return x[n]; } else { x[n] = fib(n - 1) + fib(n - 2); return x[n]; } } int main() { cin.sync_with_stdio(false); ll N, M; cin >> N >> M; ll ans = fib(N) % M; cout << ans << endl; return 0; }