NTT学习笔记
和 \(FFT\) 相对应的,把单位根换成了原根,把共轭复数换成了原根的逆元,最后输出的时候记得乘以原 \(N\) 的逆元即可. #include <bits/stdc++.h> using namespace std; #define LL long long const int MAXN = 3 * 1e6 + 10, P = 998244353, G = 3; LL a[MAXN], b[MAXN]; int N, M, limit = 1, L, r[MAXN], Gi; inline LL fastpow(LL a, LL k) { LL base = 1; while(k) { if(k & 1) base = (base * a ) % P; a = (a * a) % P; k >>= 1; } return base % P; } inline void NTT(LL *A, int type) { for (int i = 0; i < limit; i++) { if(i < r[i]) swap(A[i], A[r[i]]); } for (int mid = 1; mid < limit; mid <<= 1) { LL Wn = fastpow (type == 1 ? G : Gi , (P - 1) / (mid << 1)); for(int j