#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmax(T &x, const T &y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, const T &y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline T geti() {
  register T xi = 0;
  register char ch = getchar();
  bool f = 0;
  while (!isdigit(ch)) ch == '-' ? f = 1 : f, ch = getchar();
  while (isdigit(ch)) xi = xi * 10 + ch - 48, ch = getchar();
  return f ? -xi : xi;
}
template <typename T>
inline void pi(T k, char ch = 0) {
  if (k < 0) k = -k, putchar('-');
  if (k >= 10) pi(k / 10);
  putchar(k % 10 + '0');
  if (ch) putchar(ch);
}
const int N = 3e5 + 10;
int P;
int f[19][N];
int ifac[N], fac[N], inv[N];
inline long long fpow(long long a, int b, long long c = 1) {
  for (; b; b >>= 1, a = a * a % P)
    if (b & 1) c = c * a % P;
  return c;
}
inline void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
  ifac[n] = fpow(fac[n], P - 2);
  for (int i = n - 1; ~i; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % P;
  inv[1] = 1;
  for (int i = 2; i <= n; ++i) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
}
inline void add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
inline void sub(int &x, int y) {
  x -= y;
  x -= (x >> 31) * P;
}
inline void FMT(int *f, int n) {
  for (int l = 1; l < n; l <<= 1)
    for (int i = 0; i < n; i += l << 1)
      for (register int j = 0; j < l; ++j) add(f[i + j + l], f[i + j]);
}
inline void IFMT(int *f, int n) {
  for (int l = 1; l < n; l <<= 1)
    for (int i = 0; i < n; i += l << 1)
      for (register int j = 0; j < l; ++j) sub(f[i + j + l], f[i + j]);
}
int n, k;
int lp[N];
inline void ln(int *f, int *g, int n) {
  g[0] = 0;
  for (int i = 1; i < n; ++i) {
    g[i] = 0;
    for (int j = 1; j < i; ++j)
      g[i] = (g[i] + 1ll * f[i - j] * g[j] % P * j) % P;
    g[i] = (f[i] + 1ll * g[i] * (P - inv[i])) % P;
  }
}
inline void exp(int *f, int *g, int n) {
  g[0] = 1;
  for (int i = 1; i < n; ++i) {
    g[i] = 0;
    for (int j = 1; j <= i; ++j)
      g[i] = (g[i] + 1ll * g[i - j] * f[j] % P * j) % P;
    g[i] = (1ll * g[i] * inv[i]) % P;
  }
}
int main(void) {
  n = geti<int>(), k = geti<int>(), P = geti<int>();
  int ans = fpow(k, n);
  if (~n & 1) {
    int m = (int)log2(n) + 1;
    init(1 << m);
    for (int i = 0; i < (1 << m); ++i) f[__builtin_popcount(i)][i] = ifac[i];
    for (int i = 0; i <= m; ++i) FMT(f[i], 1 << m);
    static int F[20], G[20];
    for (int i = 0; i < (1 << m); ++i) {
      for (int j = 0; j <= m; ++j) F[j] = f[j][i];
      ln(F, G, m + 1);
      for (int j = 0; j <= m; ++j) G[j] = 1ll * G[j] * k % P;
      exp(G, F, m + 1);
      for (int j = 0; j <= m; ++j) f[j][i] = F[j];
    }
    IFMT(f[__builtin_popcount(n)], 1 << m);
    ans = (P + ans - 1ll * f[__builtin_popcount(n)][n] * fac[n] % P) % P;
  }
  pi(ans);
  return 0;
}
