#include <bits/stdc++.h>
using namespace std;
const int N = 21;
const int M = (1 << 19) + 10;
long long mod;
inline long long read(void) {
  char ch = getchar();
  long long sum = 0;
  bool f = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  if (f) sum = -sum;
  return sum;
}
inline void Add(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
  return;
}
int n, m, MLog, All, K;
int PC[M];
long long Fac[M], IFac[M], Inv[M];
long long F[N][M], G[N][M];
inline long long Pow(long long x, long long y) {
  long long sum = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) sum = sum * x % mod;
  return sum;
}
inline void FMT(long long *A, int Lim, int opt) {
  long long Mul = (opt == 0) ? 1 : mod - 1;
  for (int now = 0; now < Lim; now++)
    for (int i = 0; i < (1 << Lim); i++)
      if (i & (1 << now)) Add(A[i], A[i ^ (1 << now)] * Mul % mod);
  return;
}
inline void Exp(long long *A, long long *B, int Lim) {
  B[0] = 1;
  for (int i = 0; i < Lim - 1; i++) {
    B[i + 1] = 0;
    for (int j = 0; j <= i; j++)
      Add(B[i + 1], A[j + 1] * (j + 1) % mod * B[i - j] % mod);
    B[i + 1] = B[i + 1] * Inv[i + 1] % mod;
  }
  return;
}
inline void Ln(long long *A, long long *B, int Lim) {
  B[0] = 0;
  for (int i = 0; i < Lim - 1; i++) {
    B[i + 1] = 0;
    for (int j = 0; j <= i - 1; j++)
      Add(B[i + 1], B[j + 1] * (j + 1) % mod * A[i - j] % mod);
    B[i + 1] = mod - B[i + 1] * Inv[i + 1] % mod;
    B[i + 1] = (B[i + 1] + A[i + 1]) % mod;
  }
  return;
}
int main() {
  n = read();
  K = read();
  mod = read();
  if (n & 1) return cout << Pow(K, n), 0;
  for (int i = n; i; i >>= 1) m += (i & 1), MLog++;
  All = (1 << MLog);
  Fac[0] = 1;
  for (int i = 1; i < All; i++) Fac[i] = Fac[i - 1] * i % mod;
  IFac[All - 1] = Pow(Fac[All - 1], mod - 2);
  for (int i = All - 2; i >= 0; i--) IFac[i] = IFac[i + 1] * (i + 1) % mod;
  for (int i = All - 1; i >= 1; i--) Inv[i] = IFac[i] * Fac[i - 1] % mod;
  for (int i = 0; i < All; i++) PC[i] = PC[i >> 1] + (i & 1);
  for (int i = 0; i < All; i++) F[PC[i]][i] = IFac[i];
  for (int i = 0; i <= MLog; i++) FMT(F[i], MLog, 0);
  for (int i = 0; i < All; i++) {
    static long long Tmp1[N], Tmp2[N];
    for (int j = 0; j <= m; j++) Tmp1[j] = F[j][i];
    Ln(Tmp1, Tmp2, m + 1);
    for (int j = 0; j <= m; j++) Tmp2[j] = Tmp2[j] * K % mod;
    Exp(Tmp2, Tmp1, m + 1);
    for (int j = 0; j <= m; j++) G[j][i] = Tmp1[j];
  }
  FMT(G[m], MLog, 1);
  cout << (Pow(K, n) - G[m][n] * Fac[n] % mod + mod) % mod;
  return 0;
}
