#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, k, p, w, cnt[N], f[21][N], g[21][N], fav[N];
int qpow(int a, int b) {
  int ans = 1;
  for (; b >= 1; b >>= 1, a = (long long)a * a % p)
    if (b & 1) ans = (long long)ans * a % p;
  return ans;
}
void upd(int &a, int b) { (a += b) >= p ? a -= p : 0; }
void fwt(int *a) {
  for (int i = 1; i < (1 << w); i <<= 1)
    for (int j = 0; j < (1 << w); j += i << 1)
      for (int k = 0; k < i; k++) upd(a[j + k + i], a[j + k]);
}
void ifwt(int *a) {
  for (int i = 1; i < (1 << w); i <<= 1)
    for (int j = 0; j < (1 << w); j += i << 1)
      for (int k = 0; k < i; k++) upd(a[j + k + i], p - a[j + k]);
}
int main() {
  scanf("%d%d%d", &n, &k, &p);
  if (n & 1) return printf("%d\n", qpow(k, n)), 0;
  for (int i = 1; i <= n; ++i) cnt[i] = cnt[i & (i - 1)] + 1;
  for (int i = 0; i < 21; i++)
    if (n & (1 << i)) w = i;
  w++;
  fav[0] = fav[1] = 1;
  for (int i = 2; i <= n; ++i) fav[i] = (long long)fav[p % i] * (p - p / i) % p;
  for (int i = 1; i <= n; ++i) fav[i] = (long long)fav[i - 1] * fav[i] % p;
  for (int i = 0; i <= n; ++i) g[cnt[i]][i] = fav[i];
  for (int i = 1; i <= w; ++i) fwt(g[i]);
  fill(g[0], g[0] + (1 << w), 1);
  fill(f[0], f[0] + (1 << w), 1);
  for (int z = k; z; z >>= 1) {
    if (z & 1) {
      for (int i = w; i >= 0; --i)
        for (int j = 0; j <= i - 1; ++j)
          for (int u = 0; u <= (1 << w) - 1; ++u)
            f[i][u] = (f[i][u] + (long long)f[j][u] * g[i - j][u]) % p;
    }
    for (int i = w; i >= 0; --i)
      for (int j = 0; j <= i - 1; ++j)
        for (int u = 0; u <= (1 << w) - 1; ++u)
          g[i][u] = (g[i][u] + (long long)g[j][u] * g[i - j][u]) % p;
  }
  ifwt(f[cnt[n]]);
  int res = f[cnt[n]][n];
  for (int i = 1; i <= n; ++i) res = (long long)res * i % p;
  printf("%d\n", (qpow(k, n) + p - res) % p);
  return 0;
}
