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
#include<iostream>
using namespace std;

long long result[1000][1000] = { 0 };

long long getPot2(int n, long long p) {
	long long pot2 = 1;

	for (int i = 0; i < n - 1; i++) {
		pot2 *= 2;
		pot2 %= p;
	}

	return pot2;
}

int main() {
	int n, k;
	long long p;

	cin >> n >> k >> p;

	if (k == 0 || (n < 3 && k > 1) || (n < 5 && k > 2) || (n < 9 && k > 3)
			|| (n < 17 && k > 4) || (n < 33 && k > 5) || (n < 65 && k > 6)
			|| k > 10) {
		cout << 0;
	} else if (k == 1) {
		cout << getPot2(n, p) % p;
	} else {
		result[3][2] = 2;
		result[4][2] = 16;
		result[5][2] = 100;
		result[6][2] = 616;
		result[7][2] = 4024;
		result[8][2] = 28512;
		result[9][2] = 219664;
		result[10][2] = 1831712;
		result[11][2] = 16429152;
		result[12][2] = 157552000;
		result[13][2] = 1606874944;

		result[5][3] = 4;
		result[6][3] = 72;
		result[7][3] = 952;
		result[8][3] = 11680;
		result[9][3] = 142800;
		result[10][3] = 1788896;
		result[11][3] = 23252832;
		result[12][3] = 315549312;
		result[13][3] = 188893632;

		result[9][4] = 160;
		result[10][4] = 7680;
		result[11][4] = 233792;
		result[12][4] = 5898240;
		result[13][4] = 136280832;

		cout << result[n][k] % p;
	}
	return 0;
}