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
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define DEBUG false
#define LOG if (DEBUG) cout
typedef long long ll;
typedef unsigned long long ull;


int N, K, P;

int rozwiaz2() {
    int wynik = 1;
    int i;
    
    for (i = 1; i < N; i++) {
        wynik = (wynik * 2) % P;
    }
    
    return wynik;    
}

bool zaDuzeK() {
    ll minN;
    int bk;
    
    for (bk = 2, minN = 2; bk <= K; bk ++) {
        minN = minN * 2 - 1;
        
        if (minN > N) {
            return true;
        }        
    }
        
    return false;
}

int zTablicy() {
    ll tablica[][4] = {
        {0},
        {0},
        {2},
        {4, 2},
        {8, 16},
        {16, 100, 4},
        {32, 616, 72},
        {64, 4024, 952},
        {128, 28512, 11680},
        {256, 219664, 142800, 160},
        {512, 1831712, 1788896, 7680},
        {1024, 16429152, 23252832, 233792},
        {2048, 157552000, 315549312, 5898240}
    };
    
    ll wynik = N <= 12 ? tablica[N][K-1] : 0;
    
    return wynik % P;
}

int rozwiaz() {
    if (N == 1) {
        return 0;
    }
    
    if (K == 1) {
        return rozwiaz2();
    }
    
    if (zaDuzeK()) {
        return 0;
    }
    
    return zTablicy();
}

int main() {
    cin >> N >> K >> P;
    cout << rozwiaz();
    
    return 0;
}