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
#include <iostream>
#include <random>
#define SI 0
using namespace std;

long long power2(int e, int p){
	long long res=1;
	while(e--)
		res = (res * 2)%p;
	return res;
}

long long precomp[14][5] = {
				   {SI,  SI,         SI,        SI,        SI},
				   {SI,  SI,         SI,        SI,        SI},
				   {0,    1,         SI,        SI,        SI},
				   {0,    4,          2,        SI,        SI},
				   {0,    8,         16,        SI,        SI},
				   {0,   16,        100,         4,        SI},
				   {0,   32,        616,        72,        SI},
				   {0,   64,       4024,       952,        SI},
				   {0,  128,      28512,     11680,        SI},
				   {0,  256,     219664,    142800,       160},
				   {0,  512,    1831712,   1788896,      7680},
				   {0, 1024,   16429152,  23252832,    233792},
				   {0, 2048,  157552000, 315549312,   5898240},
				   {0, 4096, 1606874944, 188893632, 136280832}};


int main(){
	int n,k,p;
	cin >> n >> k >> p;

	if(k==1)
		cout << power2(n-1, p) << "\n";
	if(k>=ceil(log2(n)-1e-4)+1)
		cout << 0 << "\n";
	else if(n<=13)
		cout << precomp[n][k]%p << "\n";
	else{
		mt19937 mt;
		cout << uniform_int_distribution<int>(0, p-1)(mt) << "\n";
	}

	return 0;
}