This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub tatyam-prime/ICPC_notebook
#include "src/FPS/FFT.hpp"
void fft(vector<mm>& a)
vector<mm> conv(vector<mm> a, vector<mm> b)
$O(n \log n)$ 時間
fft()
// {998244353, 3}, {1811939329, 13}, {2013265921, 31} mm g = 3; // 原始根 void fft(vector<mm>& a) { ll n = sz(a), lg = __lg(n); assert((1 << lg) == n); vector<mm> b(n); rep(l, 1, lg + 1) { ll w = n >> l; mm s = 1, r = g.pow(mod >> l); for(ll u = 0; u < n / 2; u += w) { rep(d, 0, w) { mm x = a[u << 1 | d], y = a[u << 1 | w | d] * s; b[u | d] = x + y; b[n >> 1 | u | d] = x - y; } s *= r; } swap(a, b); } } vector<mm> conv(vector<mm> a, vector<mm> b) { if(a.empty() || b.empty()) return {}; size_t s = sz(a) + sz(b) - 1, n = bit_ceil(s); // if(min(sz(a), sz(b)) <= 60) 愚直に掛け算 a.resize(n); b.resize(n); fft(a); fft(b); mm inv = mm(n).inv(); rep(i, 0, n) a[i] *= b[i] * inv; reverse(1 + all(a)); fft(a); a.resize(s); return a; }
#line 1 "src/FPS/FFT.hpp" // {998244353, 3}, {1811939329, 13}, {2013265921, 31} mm g = 3; // 原始根 void fft(vector<mm>& a) { ll n = sz(a), lg = __lg(n); assert((1 << lg) == n); vector<mm> b(n); rep(l, 1, lg + 1) { ll w = n >> l; mm s = 1, r = g.pow(mod >> l); for(ll u = 0; u < n / 2; u += w) { rep(d, 0, w) { mm x = a[u << 1 | d], y = a[u << 1 | w | d] * s; b[u | d] = x + y; b[n >> 1 | u | d] = x - y; } s *= r; } swap(a, b); } } vector<mm> conv(vector<mm> a, vector<mm> b) { if(a.empty() || b.empty()) return {}; size_t s = sz(a) + sz(b) - 1, n = bit_ceil(s); // if(min(sz(a), sz(b)) <= 60) 愚直に掛け算 a.resize(n); b.resize(n); fft(a); fft(b); mm inv = mm(n).inv(); rep(i, 0, n) a[i] *= b[i] * inv; reverse(1 + all(a)); fft(a); a.resize(s); return a; }