标签:div class inline pre code int level tran line
ll result_len,result[maxn],level=0,trans[maxn]; ll quick(ll a,ll b,ll m) { ll ans=1; while(b>0) { if(b&1) ans=ans*a%m; a=a*a%m; b>>=1; } return ans; } inline void NTT(ll *A, int type) { for(int i = 0; i < result_len; i++) if(i < trans[i]) swap(A[i], A[trans[i]]); for(int mid = 1; mid < result_len; mid <<= 1) { ll Wn = quick( type == 1 ? G : Gi , (mod - 1) / (mid << 1),mod); for(int j = 0; j < result_len; j += (mid << 1)) { ll w = 1; for(int k = 0; k < mid; k++, w = (w * Wn) % mod) { int x = A[j + k], y = w * A[j + k + mid] % mod; A[j + k] = (x + y) % mod, A[j + k + mid] = (x - y + mod) % mod; } } } } void ntt(ll *a,int a_len,ll *b,int b_len) { result_len=1;level=0; while(result_len<=a_len+b_len) { result_len<<=1; level++; } for(int i=0;i<result_len;i++) trans[i]=(trans[i>>1]>>1)|((i&1)<<(level-1)); NTT(a, 1); NTT(b, 1); for(int i=0;i<result_len;i++) result[i]=(a[i]*b[i])%mod; NTT(result,-1); ll inv=quick(result_len, mod-2, mod); for(int i=0;i<result_len;i++) result[i]=(result[i]*inv)%mod; }
标签:div class inline pre code int level tran line
原文地址:https://www.cnblogs.com/King-of-Dark/p/13024501.html