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
#include <cstdio>

long long precalc[11][3] =
{
  {2, 0, 0},  //3
  {16, 0, 0},  //4
  {100, 4, 0},  //5
  {616, 72, 0}, //6
  {4024, 952, 0}, //7
  {28512, 11680, 0}, //8
  {219664, 142800, 160}, //9
  {1831712, 1788896, 7680}, //10
  {16429152, 23252832, 233792}, //11
  {157552000, 315549312, 5898240}, //12
  {1606874944, 4483860928LL, 136280832}, //13
};

int main()
{
  int n, k, p;
  scanf("%d %d %d", &n, &k, &p);
  
  int pot = 1;
  int wykladnik = 0;

  while (pot < n)
  {
    pot *= 2;
    wykladnik++;
  }
  
  if (k > wykladnik)
  {
    printf("0\n");
    return 0;
  }
  
  if (k == 1)
  {
    long long r = 1;
    for (int i = 0; i < n - 1; i++)
    {
      r *= 2;
      r %= p;
    }
    printf("%lld\n", r);
    return 0;
  }

  if (n <= 13)  
  {
    printf("%lld\n", precalc[n - 3][k - 2] % p);
  }
  else
  {
    printf("0\n");
  }
  return 0;
}