/*
* Copyright (C) 2018 Paweł Widera
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int result, limit;
int n, k, q;
cin >> n >> k >> q;
// simplest case
if (k == 1) {
result = 1;
for (int i = 1; i < n; ++i) {
result = (result * 2) % q;
}
cout << 0 << endl;
return 0;
}
// check if any result is possible at all
if (k >= 2) {
limit = 1;
for (int i = 1; i < k; ++i) {
limit = 2 * limit - 1;
}
if (k < limit) {
cout << 0 << endl;
return 0;
}
}
int total = 1;
for (int i = 2; i < n; ++i) {
total = (total * i) % q;
}
vector<long long int> results;
if (k == 2) {
results = {2, 16, 100, 616, 4024, 28512, 219664, 1831712, 16429152, 157552000, 1606874944};
n -= 3;
}
if (k == 3) {
results = {4, 72, 952, 11680, 142800, 1788896, 23252832, 315549312, 4483860928};
n -= 5;
}
if (k == 4) {
results = {160, 7680, 233792, 5898240};
n -= 9;
}
if (!results.empty() && n < (int)results.size()) {
cout << results[n] % q << endl;
} else {
cout << "dunno..." << endl;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | /* * Copyright (C) 2018 Paweł Widera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html */ #include <iostream> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int result, limit; int n, k, q; cin >> n >> k >> q; // simplest case if (k == 1) { result = 1; for (int i = 1; i < n; ++i) { result = (result * 2) % q; } cout << 0 << endl; return 0; } // check if any result is possible at all if (k >= 2) { limit = 1; for (int i = 1; i < k; ++i) { limit = 2 * limit - 1; } if (k < limit) { cout << 0 << endl; return 0; } } int total = 1; for (int i = 2; i < n; ++i) { total = (total * i) % q; } vector<long long int> results; if (k == 2) { results = {2, 16, 100, 616, 4024, 28512, 219664, 1831712, 16429152, 157552000, 1606874944}; n -= 3; } if (k == 3) { results = {4, 72, 952, 11680, 142800, 1788896, 23252832, 315549312, 4483860928}; n -= 5; } if (k == 4) { results = {160, 7680, 233792, 5898240}; n -= 9; } if (!results.empty() && n < (int)results.size()) { cout << results[n] % q << endl; } else { cout << "dunno..." << endl; } return 0; } |
English