結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | olphe |
提出日時 | 2017-06-09 22:36:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,004 bytes |
コンパイル時間 | 1,993 ms |
コンパイル使用メモリ | 111,084 KB |
実行使用メモリ | 42,688 KB |
最終ジャッジ日時 | 2023-10-23 22:07:16 |
合計ジャッジ時間 | 3,351 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,372 KB |
testcase_01 | AC | 2 ms
4,372 KB |
testcase_02 | AC | 2 ms
4,372 KB |
testcase_03 | AC | 2 ms
4,372 KB |
testcase_04 | AC | 2 ms
4,372 KB |
testcase_05 | AC | 2 ms
4,372 KB |
testcase_06 | AC | 2 ms
4,372 KB |
testcase_07 | AC | 2 ms
4,372 KB |
testcase_08 | AC | 2 ms
4,372 KB |
testcase_09 | AC | 4 ms
6,348 KB |
testcase_10 | AC | 20 ms
12,492 KB |
testcase_11 | AC | 88 ms
42,688 KB |
testcase_12 | AC | 87 ms
42,628 KB |
testcase_13 | AC | 87 ms
42,688 KB |
testcase_14 | AC | 88 ms
42,688 KB |
ソースコード
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "math.h" #include "utility" #include "string" #include "map" #include "unordered_map" #include "iomanip" #include "random" using namespace std; const long long int MOD = 1000000007; list<long long int> Prime(int M) { list<long long int>P; P.push_back(2); P.push_back(3); for (int i = 5; i <= M; i += 6) { bool flag = true; for (auto j : P) { if (i%j == 0) { flag = false; break; } } if (flag)P.push_back(i); flag = true; for (auto j : P) { if ((i + 2) % j == 0) { flag = false; break; } } if (flag)P.push_back(i + 2); } return P; } long long int N, K, Q, M; long long int num[5000001]; int main() { ios::sync_with_stdio(false); cin >> N >> M; num[1] = 0; num[2] = 1; for (int i = 3; i <= N; i++) { num[i] = num[i - 1] + num[i - 2]; num[i] %= M; } cout << num[N] << endl; return 0; }