多項式重工業基地

2022-06-28 06:18:15 字數 3957 閱讀 7020

未完待續……(只是給自己存個板子)

快速傅利葉變換

#include using namespace std; const int maxn = 2e6 + 1e2;

struct cp

; } inline cp operator -(const cp& b) const ; }

inline cp operator *(const cp& b) const ; }

};namespace fft

} inline void fft(cp a, int v)

; for (int r = mid << 1, j = 0; j < lim; j += r)

; for (int k = 0; k < mid; k++, w = w * wn)

}} for (int i = 0; i < lim; i++) (v > 0) ? (a[i].x /= lim, a[i].y /= lim) : (a[i].x *= lim, a[i].y /= lim);

} inline void conv(cp a, cp b, cp c)

}cp a[maxn], b[maxn], c[maxn]; int n, m; int main()

快速數論變換:

#include using namespace std; const int maxn = 5e5 + 1e2, mod = 998244353, g = 3, h = 332748118;

namespace fft

} inline int fpow(int x, int k)

return res;

} inline void fft(int a, int v)

}} int inv = fpow(lim, mod - 2);

for (int i = 0; i < lim; i++) (v > 0) ? (a[i] = a[i] * 1ll * inv % mod) : (a[i] = a[i] * 1ll * lim % mod);

} inline void conv(int a, int b, int c)

}int a[maxn], b[maxn], c[maxn]; int n, m; int main()

快速莫比烏斯/沃爾什變換:

namespace fwt

inline void or(modint f, modint t)

inline void and(modint f, modint t)

inline void xor(modint f, modint t) }

inline void conv(modint a, modint b, modint c)

}

modint 類(亂入):

int ttmp; struct modint

modint()

inline modint &operator =(int o)

inline modint &operator +=(modint b)

inline modint &operator -=(modint b)

inline modint &operator *=(modint b)

inline modint operator ^(int k)

return res;

} inline modint operator /=(modint b)

inline modint operator /=(int b)

inline modint operator +(modint b) const

inline modint operator -(modint b) const

inline modint operator *(modint b) const

inline modint operator /(modint b) const

};

多項式乘法逆:

#include using namespace std; const int maxn = 1e6 + 1e2, mod = 998244353, g = 3, gi = 332748118;

namespace ntt

} inline int qpow(int x, int k)

return res;

} inline void ntt(int a, int type)

}} int inv = qpow(lim, mod - 2);

for (int i = 0; i < lim; i++) (type == 1) ? (a[i] = a[i] * 1ll * inv % mod) : (a[i] = a[i] * 1ll * lim % mod);

} int a[maxn], b[maxn]; inline void conv(int a, int b, int c, int n, int m, int k) }

int t[maxn]; inline void polyinv(int f, int g, int n)

int m = (n + 1) >> 1; polyinv(f, g, m);

ntt::conv(f, g, t, n - 1, m - 1, n);

for (int i = 0; i < n; i++) t[i] = -t[i]; t[0] += 2;

ntt::conv(g, t, g, m - 1, n - 1, n);

}int f[maxn], g[maxn], n;

int main()

多項式開根(接在逆元的後面):

int u[maxn]; inline void polysqrt(int f, int g, int n)

int m = (n + 1) >> 1; polysqrt(f, g, m);

polyinv(g, u, n), ntt::conv(u, f, u, n - 1, n - 1, n);

int inv = ntt::qpow(2, mod - 2);

for (int i = 0; i < n; i++) g[i] = (g[i] + u[i]) * 1ll * inv % mod;

}

子集卷積:

#include using namespace std; const int maxn = 1 << 22, mod = 1e9 + 9;

inline void fwt(int f, int n, int t)

int n, a[21][maxn], b[21][maxn], c[21][maxn], t[maxn];

int main()

for (int i = 0; i <= n; i++) fwt(c[i], n, -1);

for (int i = 0; i < (1 << n); i++) cout << (c[__builtin_popcount(i)][i] + mod) % mod << ' ';

}

ln & exp 指數 / 對數函式

int v[maxn]; inline void polyln(int f, int g, int n)

int w[maxn]; inline void polyexp(int f, int g, int n)

int m = (n + 1) >> 1; polyexp(f, g, m);

polyln(g, w, n); for (int i = 0; i < n; i++) w[i] = (- w[i] + f[i]) % mod; w[0]++;

ntt::conv(w, g, g, n - 1, m - 1, n);

}

未完待續……敬請期待(bushi

MATLAB多項式及多項式擬合

多項式均表示為陣列形式,陣列元素為多項式降冪係數 1.polyval函式 求多項式在某一點或某幾個點的值.p 1,1,1 x 2 x 1 x 1,0,1 y polyval p,x 另外求函式在某一點或某幾個點的值可以用函式feval.x 1,0,1 y feval x exp x x 注意用的乘法...

數學 多項式 多項式求逆

多項式求逆 前置知識 ntt 給定乙個多項式 f left x right 求乙個多項式 g left x right 使得 f left x right g left x right equiv 1 left bmod 998244353 right 考慮遞迴求解。假定現在已經求出了 g 0 le...

matlab多項式與非多項式擬合

擬合標準 1 原始資料向量與擬合向量之間的距離最小,該距離的度量一般使用誤差平方和表示,即均方誤差 r q y 22 2 當均方誤差最小時,說明構造的擬合向量與原始向量最為接近,這種曲線擬合的方法稱為最小二乘法 3 計算均方誤差最小時的擬合係數,可以通過微積分中求解極值的方法實現 多項式擬合 1 多...