不知道为啥只过了两个点,这份代码调了3天了,真的自闭了。大佬带我!
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
int read();
int M(int x) { return x >= mod ? x - mod : x; }
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }
int fsp(long long bs, int p) {
int rt = 1;
while (p) {
if (p & 1) rt = bs * rt % mod;
bs = bs * bs % mod, p >>= 1;
}
return rt;
}
int fac[300005], caf[300005], lim = 300000;
void init() {
fac[0] = 1;
for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
caf[lim] = fsp(fac[lim], mod - 2);
for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}
int C(int x, int y) {
return x < y ? 0 : 1ll * fac[x] * caf[y] % mod * caf[x - y] % mod;
}
int inv(int x) { return 1ll * caf[x] * fac[x - 1] % mod; }
int L = 1 << 18;
int O[300005];
void initO() {
O[0] = 1, O[1] = fsp(3, (mod - 1) / L);
for (int i = 2; i < L; ++i) O[i] = 1ll * O[i - 1] * O[1] % mod;
}
int R[300005];
void getR(int len, int w) {
for (int i = 1; i < len; ++i) R[i] = R[i >> 1] >> 1 | ((i & 1) << w - 1);
}
struct Poly {
int x[300005];
int &operator[](int p) { return x[p]; }
void mem(int len, int st = 0) { memset(x + st, 0, len << 2); }
void cpy(Poly &y, int len) { memcpy(x, y.x, len << 2); }
void cpy(int *y, int len) { memcpy(x, y, len << 2); }
void der(int len) {
for (int i = 0; i < len - 1; ++i) x[i] = 1ll * (i + 1) * x[i + 1] % mod;
x[len - 1] = 0;
}
void inter(int len) {
for (int i = len - 1; i >= 1; --i) x[i] = 1ll * inv(i) * x[i - 1] % mod;
x[0] = 0;
}
void dft(int len) {
for (int i = 1; i < len; ++i) R[i] > i ? swap(x[i], x[R[i]]) : void();
for (int l = 2; l <= len; l <<= 1)
for (int i = 0, m = l >> 1, dO = L / l; i < len; i += l)
for (int j = i, t, *tO = O; j < i + m; ++j, tO += dO) {
t = 1ll * *tO * x[j + m] % mod;
x[j + m] = M(x[j] - t + mod), x[j] = M(x[j] + t);
}
}
void idft(int len) {
int ny = (dft(len), reverse(x + 1, x + len), fsp(len, mod - 2));
for (int i = 0; i < len; ++i) x[i] = 1ll * x[i] * ny % mod;
}
void Inv(int len) {
static Poly y, tx, ty;
y.mem(len << 1), tx.mem(len << 1), ty.mem(len << 1);
y[0] = fsp(x[0], mod - 2);
for (int tl = 2, w = 1; tl <= len; tl <<= 1, ++w) {
tx.cpy(x, tl), ty.cpy(y, tl), getR(tl << 1, w + 1);
tx.dft(tl << 1), ty.dft(tl << 1);
for (int i = 0; i < (tl << 1); ++i)
tx[i] = 1ll * tx[i] * ty[i] % mod * ty[i] % mod;
tx.idft(tl << 1);
for (int i = 0; i < tl; ++i) y[i] = M(M(y[i] << 1) - tx[i] + mod);
}
cpy(y, len);
}
void Ln(int len) {
int w = 0;
while ((1 << w) < len) ++w;
static Poly y;
y.mem(len << 1), y.cpy(x, len), y.Inv(len), der(len);
getR(len << 1, w + 1), y.dft(len << 1), dft(len << 1);
for (int i = 0; i < (len << 1); ++i) x[i] = 1ll * x[i] * y[i] % mod;
idft(len << 1), mem(len, len), inter(len);
}
void exp(int len, int t = 1) {
static Poly y, tx, ty;
y.mem(len << 1), tx.mem(len << 1), ty.mem(len << 1), y[0] = t;
for (int tl = 2, w = 1; tl <= len; tl <<= 1, ++w) {
ty.cpy(y, tl), ty.Ln(tl);
for (int i = 0; i < tl; ++i) tx[i] = M(x[i] - ty[i] + mod);
tx[0] = t, ty.cpy(y, tl), getR(tl << 1, w + 1);
tx.dft(tl << 1), ty.dft(tl << 1);
for (int i = 0; i < (tl << 1); ++i)
ty[i] = 1ll * tx[i] * ty[i] % mod;
ty.idft(tl << 1), y.cpy(ty, tl);
}
cpy(y, len);
}
} F, G, dG, nG;
void prework() {
int len = 1 << 17;
for (int i = 0; i < len; ++i) F[i] = 1ll * fsp(2, C(i, 2)) * caf[i] % mod;
G.cpy(F, len), G.Ln(len);
for (int i = 0; i < len; ++i) G[i] = 1ll * G[i] * i % mod;
dG.cpy(G, len), dG.der(len), dG.dft(len << 1);
}
void work(int n) {
int len = 1 << 17;
nG.mem(len << 1);
for (int i = 0; i < len; ++i) nG[i] = 1ll * G[i] * (mod - n) % mod;
nG.exp(len), nG.dft(len << 1);
for (int i = 0; i < (len << 1); ++i) nG[i] = 1ll * nG[i] * dG[i] % mod;
nG.idft(len << 1);
printf("%d\n", 1ll * nG[n - 1] * inv(n) % mod * fac[n - 1] % mod);
}
int main() {
init(), initO(), prework();
for (int i = 1; i <= 5; ++i) work(read());
return 0;
}
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}