标签:std 变换 pen ace include play namespace make ever
不证明了。
未完待续,随学随更。
以下默认 \(A(x)\) 为 \((n - 1)\) 次多项式 \(A(x) = \sum_{i = 0}^{n - 1} a_i x^i\),且 \(n\) 为 \(2\) 的整数幂。
\[A_(\omega_n^k)~=~A_0(\omega_m^k) + \omega_n^kA_1(\omega_m^k)\]
\[A(\omega_n^{k + m})~=~A_0(\omega_m^k) - \omega_n^kA_1(\omega_m^k)\]
其中 \(m = \frac{n - 1}{2}\),\(A_0(x) = \sum_{i = 0}^m a_{2i} x^i\),\(A_1(x) = \sum_{i = 0}^m a^{2i + 1}x^i\)。\(\omega_n\) 代表最小的 \(n\) 次单位根/原根。
\[B_{2k}(x) \equiv 2 B_{k}(x) - A_{2k}(x) \times B_{k}^{2}(x) \pmod {x^{2k}}\]
其中 \(A_k(x)\) 代表 \(A\) 的前 \(k\) 项;\(B_k(x)~=~A_k^{-1}(x)\)。
注意:\(B_k(x)\) 不一定是 \(A_n(x)\) 乘法逆的前 \(k\) 项,它只是 \(A_n(x)\) 前 \(k\) 项的乘法逆。
设
\[B(x) = \ln A(x)\]
有
\[B'(x)~\equiv~A'(x) A^{-1}(x) \pmod {x^n}\]
则
\[B(x)~=~\int B'(x) \text{d}x\]
求导、积分公式:
\[f(x) = Cx^a~~\Rightarrow~~f'(x) = C(a - 1)x^{a - 1}\]
\[f(x) = Cx^a ~~\Rightarrow~~ \int f(x) \text{d}x = \frac{C}{a + 1} x^{a + 1}\]
其中 \(C\) 是常数。对于多项式,二者均是线性可加的。
#include <cstdio>
#include <cstring>
#include <algorithm>
template <typename T>
void qr(T &x);
template <typename T>
void qw(T x, const char Ch, const bool NeedPutChar);
namespace Poly {
const int G = 3;
const int MOD = 998244353;
const int PHI = 998244352;
const int DPHI = 998244351;
const int SzI = sizeof(int);
const int SzL = sizeof(long long int);
void Init(int *const A, const int N) {
for (int i = 0; i < N; ++i) {
qr(A[i]);
}
}
void Print(int *const A, const int N) {
int DN = N - 1;
for (int i = 0; i < DN; ++i) {
qw(A[i], ' ', true);
}
qw(A[DN], '\n', true);
}
void GetN(int n, int &N) {
N = 1;
while (N < n) N <<= 1;
}
int mpow(int x, int y) {
int _ret = 1;
while (y) {
if (y & 1) _ret = 1ll * x * _ret % MOD;
x = 1ll * x * x % MOD;
y >>= 1;
}
return _ret;
}
int tax[maxn], taxlen;
void GetRev(const int N) {
int p = 1, d = N >> 1;
for (int w = p; w < N; w = p) {
for (int i = 0; i < w; ++i) {
tax[p++] = tax[i] | d;
}
d >>= 1;
}
taxlen = N;
}
void MakeRev(int *const A, const int N) {
for (int i = 1; i < N; ++i) if (tax[i] > i) {
std::swap(A[i], A[tax[i]]);
}
}
void Modint(int &x) {
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
void NTT(int *const A, const int N) {
if (taxlen != N) {
GetRev(N);
}
MakeRev(A, N);
for (int w = 2, M = 1; w <= N; w <<= 1) {
int Wn = mpow(G, PHI / w);
for (int L = 0; L < N; L += w) {
ll g = 1;
for (int i = L, lm = L + M, j = lm; i < lm; ++i, ++j) {
ll x = A[i], y = A[j];
A[i] = (x + g * y) % MOD; A[j] = (x - g * y) % MOD;
(g *= Wn) %= MOD;
}
}
M = w;
}
for (int i = 0; i < N; ++i) {
Modint(A[i]);
}
}
void GetInv(int *const A, int *const B, const int N) {
static int C[maxn];
B[0] = mpow(A[0], DPHI);
for (int w = 2, M = 4; w <= N; M <<= 1) {
memcpy(C, A, w * SzI);
NTT(B, M); NTT(C, M);
for (int i = 0; i < M; ++i) {
B[i] = (B[i] << 1) % MOD - 1ll * C[i] * B[i] % MOD * B[i] % MOD;
Modint(B[i]);
}
NTT(B, M);
std::reverse(B + 1, B + M);
for (int i = 0, iv = mpow(M, DPHI); i < w; ++i) {
B[i] = 1ll * B[i] * iv % MOD;
}
memset(B + w, 0, w * SzI);
w = M;
}
}
void GetDer(int *const A, int *const B, const int N) {
for (int i = 1; i < N; ++i) {
B[i - 1] = 1ll * A[i] * i % MOD;
}
B[N - 1] = 0;
}
void GetInte(int *const A, int *const B, const int N) {
B[0] = 0;
for (int i = 1; i < N; ++i) {
B[i] = 1ll * A[i - 1] * mpow(i, DPHI) % MOD;
}
}
void GetLn(int *const A, int *const B, const int N) {
static int C[maxn];
GetDer(A, B, N);
GetInv(A, C, N);
int M = N << 1;
NTT(B, M); NTT(C, M);
for (int i = 0; i < M; ++i) {
C[i] = 1ll * B[i] * C[i] % MOD;
}
NTT(C, M);
std::reverse(C + 1, C + M);
for (int i = 0, iv = mpow(M, DPHI); i < N; ++i) {
C[i] = 1ll * C[i] * iv % MOD;
}
GetInte(C, B, N);
}
}
标签:std 变换 pen ace include play namespace make ever
原文地址:https://www.cnblogs.com/yifusuyi/p/12157488.html