题解:CF1667E Centroid Probabilities
你说得对,但是我口胡完
考虑先算
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353, G = 3, GI = (P + 1) / 3;
int n, L;
ll fac[200005], ifac[200005], f[1000005], g[1000005];
ll QPow(ll a, ll b) {
ll res = 1;
for (; b; b >>= 1, a = a * a % P) if (b & 1) res = res * a % P;
return res;
}
ll C(int n, int m) { return fac[n] * ifac[m] % P * ifac[n - m] % P; }
int r[1000005], lim, llim;
void SetLim(int x) {
llim = __lg(x - 1) + 1, lim = 1 << llim;
for (int i = 0; i < lim; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (llim - 1));
}
void NTT(ll *a, int tp) {
for (int i = 0; i < lim; i++) if (i < r[i]) swap(a[i], a[r[i]]);
for (int w = 1; w < lim; w <<= 1) {
ll omg = QPow(tp == 1 ? G : GI, (P - 1) / (w << 1));
for (int i = 0; i < lim; i += (w << 1)) {
ll t = 1;
for (int j = 0; j < w; j++) {
ll x = a[i + j], y = a[i + j + w] * t % P;
a[i + j] = (x + y) % P;
a[i + j + w] = (x - y + P) % P;
t = t * omg % P;
}
}
}
if (tp == -1) {
ll iv = QPow(lim, P - 2);
for (int i = 0; i < lim; i++) a[i] = a[i] * iv % P;
}
}
int main() {
scanf("%d", &n), L = n / 2 + 1;
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % P;
ifac[n] = QPow(fac[n], P - 2);
for (int i = n; i; i--) ifac[i - 1] = ifac[i] * i % P;
f[1] = 1;
for (int i = 2; i <= n; i++) {
f[i] = f[i - 1] * (i - 1) % P;
if (i > L) {
f[i] -= f[i - L] * f[L] % P * C(i - 2, L - 1) % P;
f[i] = (f[i] + P) % P;
}
}
printf("%lld ", f[n]);
for (int i = 1; i < n - L + 1; i++) f[i] = 0;
for (int i = n - L + 1; i <= n; i++) f[i] = f[i] * ifac[i - 1] % P * fac[n - i - 1] % P;
for (int i = 0; i <= n + 1; i++) g[i] = ifac[n - i + 1];
reverse(f, f + n + 1);
SetLim(n * 2 + 5);
NTT(f, 1), NTT(g, 1);
for (int i = 0; i < lim; i++) f[i] = f[i] * g[i] % P;
NTT(f, -1);
for (int i = 2; i <= n; i++) {
printf("%lld ", f[n + i] % P * fac[n - i] % P * (i - 1) % P);
}
return 0;
}