longlongint n, HA, fac[MAXN], inv[MAXN], siz[MAXN], dp[MAXN]; std::vector<int> head[MAXN << 1];
/* long long int getll() { long long int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * x + 1ll * ch - 1ll * '0'; ch = getchar(); } return 1ll * s * x; } void putll(long long int x) { if (x < 0) { putchar('-'); x = -x; } putll(x / 10); putchar(x % 10 + '0'); } */
longlongintfastPow(longlongint a, longlongint b){ if (b == 0) return1; if (b == 1) return a % HA; longlongint ret = 1; while (b) { if (b & 1) ret = ret * a % HA; a = a * a % HA; b >>= 1; } return ret; }
longlongintC(longlongint m, longlongint n){ // 洛谷上数据水不用 Lucas 定理 // n! / (m!(n - m)!) return fac[n] * inv[m] % HA * inv[n - m] % HA; }
inlinevoidaddEdge(int prev, int next){ head[prev].push_back(next); head[next].push_back(prev); }
voidDFS(longlongint father = 0, longlongint root = 1){ siz[root] = 1; dp[root] = 1; for (int i = 0, ss = head[root].size(); i < ss; ++i) { int next = head[root][i]; if (father == next) continue; DFS(root, next); siz[root] += siz[next]; dp[root] = 1ll * dp[root] * C(siz[next], siz[root] - 1) % HA * dp[next] % HA; } }
intmain(){ //n = getll(); HA = getll(); scanf("%lld %lld", &n, &HA); fac[0] = 1; inv[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = fac[i - 1] * i % HA; inv[i] = fastPow(fac[i], HA - 2); int lson = (i << 1), rson = (i << 1 | 1); if (lson <= n) addEdge(i, lson); if (rson <= n) addEdge(i, rson); } DFS(); //putll(dp[1] % HA); printf("%lld\n", dp[1] % HA); return0; }