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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;

const int INF = 1000000009;
const LL LINF = 1000000000000000009LL;

#define FOR(i, b, e) for(int i = b; i <= e; ++i) 
#define FORD(i, b, e) for(int i = b; i >= e; --i) 
#define REP(i, n) FOR(i, 0, n-1)
#define REV(i, n) FORD(i, n-1, 0)
#define PB push_back
#define PP pop_back
#define MP make_pair
#define ST first
#define ND second
#define SIZE(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

#define DEBUG(s) s

const int N = 100005;

LL n, k, p;

int dp[1005][1005];

void init()
{
	dp[3][2] = 2;
	dp[4][2] = 16;
	dp[5][2] = 100;
	dp[6][2] = 616;
	dp[7][2] = 4024;
	dp[8][2] = 28512;
	dp[9][2] = 219664;
	dp[10][2] = 1831712;
	dp[11][2] = 16429152;
	dp[5][3] = 4;
	dp[6][3] = 72;
	dp[7][3] = 952;
	dp[8][3] = 11680;
	dp[9][3] = 142800;
	dp[10][3] = 1788896;
	dp[11][3] = 23252832;
	dp[9][4] = 160;
	dp[10][4] = 7680;
	dp[11][4] = 233792;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>n>>k>>p;
	
	init();
	
	if(k == 1)
	{
		LL res = 1;
		FOR(i, 2, n)
		{
			res*=2;
			res%=p;
		}
		
		cout<<res<<"\n";
	}
	else if(ceil(log2(n)) < k)
	{
		cout<<0<<"\n";
	}
	else
	{
		cout<<dp[n][k];
	}
	
	
	//~ FOR(i, 1, 11)
	//~ {
		//~ cout<<i<<" : ";
		//~ FOR(j, 1, 11)
		//~ {
			//~ cout<<dp[i][j]<<" ";
		//~ }
		//~ cout<<"\n";
	//~ }
	
 
    
	return 0;
}