#include <iostream>
#include <cmath>
using namespace std;
int array[12][12] = {
{0}, // 0
{0, 1},
{0, 2, 0},
{0, 4, 2, 0}, // 3
{0, 8, 16, 0, 0},
{0, 16, 100, 4, 0, 0},
{0, 32, 616, 72, 0, 0, 0},
{0, 64, 4024, 952, 0, 0, 0, 0},
{0, 128, 28512, 11680, 0, 0, 0, 0, 0}, // 8
{0, 256, 219664, 142800, 160, 0, 0, 0, 0, 0}, // 9
{0, 512, 1831712, 1788896, 7680, 0, 0, 0, 0, 0, 0},
{0, 1024, 16429152, 23252832, 233792, 0, 0, 0, 0, 0, 0, 0}
};
int main() {
int N, K, P;
cin >> N >> K >> P;
if (ceil(log2(N)) < K) {
cout << 0 << endl;
} else if (N < 12) {
cout << array[N][K] % P << endl;
} else {
if (K == 0) cout << 0 << endl;
else if (K == 1) {
int r = 1;
for (int i = 0; i < N; ++i) r = (r * 2) % P;
cout << r << endl;
} else while(true);
}
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 | #include <iostream> #include <cmath> using namespace std; int array[12][12] = { {0}, // 0 {0, 1}, {0, 2, 0}, {0, 4, 2, 0}, // 3 {0, 8, 16, 0, 0}, {0, 16, 100, 4, 0, 0}, {0, 32, 616, 72, 0, 0, 0}, {0, 64, 4024, 952, 0, 0, 0, 0}, {0, 128, 28512, 11680, 0, 0, 0, 0, 0}, // 8 {0, 256, 219664, 142800, 160, 0, 0, 0, 0, 0}, // 9 {0, 512, 1831712, 1788896, 7680, 0, 0, 0, 0, 0, 0}, {0, 1024, 16429152, 23252832, 233792, 0, 0, 0, 0, 0, 0, 0} }; int main() { int N, K, P; cin >> N >> K >> P; if (ceil(log2(N)) < K) { cout << 0 << endl; } else if (N < 12) { cout << array[N][K] % P << endl; } else { if (K == 0) cout << 0 << endl; else if (K == 1) { int r = 1; for (int i = 0; i < N; ++i) r = (r * 2) % P; cout << r << endl; } else while(true); } return 0; } |
English