int n, mod; int fac[maxn], finv[maxn]; intksm(int x,int mi){ intres(1); while(mi) { if(mi & 1) res = 1ll * res * x % mod; mi >>= 1; x = 1ll * x * x % mod; } return res; }
voidinit(int x){ fac[0] = 1; for(int i = 1; i <= x; ++ i) fac[i] = 1ll * fac[i - 1] * i % mod; finv[x] = ksm(fac[x], mod - 2); for(int i = x - 1; i >= 0; -- i) finv[i] = 1ll * finv[i + 1] * (i + 1) % mod; }
int vis[maxn][maxn][50], f[maxn][maxn][50]; int a1;
intdfs(int dep,int sum,int K,int lim){ if(vis[dep][sum][K]) return f[dep][sum][K]; vis[dep][sum][K] = 1; int& ret = f[dep][sum][K]; ret = 0; if(K < lim && dep < K) return0; if(K == lim) { if(dep < n) ret = finv[n - dep]; return ret; } int nx = n + 1 - K - a1; for(int j = 0; dep + j <= n && j * nx + sum <= a1; ++ j) ret = (ret + 1ll * dfs(dep + j, j * nx + sum, K + 1, lim) * finv[j] % mod) % mod; return ret; }
signedmain(){ int i, j; r1(n, mod); init(n); intans(0); int up; if(8 * n < 25) up = n; else up = sqrt(8 * n - 25) / 2 + 1; // printf("up = %d\n", up); for(int lim = 0; lim <= up; ++ lim) { memset(vis, 0, sizeof(vis)); a1 = n + 1 - lim; int x = dfs(0, 0, 0, lim); // if(x == 0) break; ans = (ans + x) % mod; } ans = 1ll * ans * fac[n] % mod; printf("%d\n", ans); return0; }