ACM模板库

ACM模板库


FWT_and

<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/8298c556a17eda943e854b62c22b1eb3" alt="" /> <img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/b3c376bb19f89dae1f53c91372f1e5df" alt="" /></p> <pre><code class="language-cpp">#include &lt;iostream&gt; using namespace std; typedef long long ll; const int maxn = 100005, mod = 998244353; ll A[maxn], b[maxn];//注意从下标为0开始存值 void FWT_and(ll *a, int n, int opt = 1){ for(int i = 1; i &lt; n; i &lt;&lt;= 1){ for(int p = i &lt;&lt; 1, j = 0; j &lt; n; j += p){ for(int k = 0; k &lt; i; k++){ if(opt == 1) a[j+k] = (a[j+k] + a[i+j+k]) % mod; else a[j+k] = (a[j+k] + mod - a[i+j+k]) % mod; } } } } int main(){ int n, tn = 1; scanf("%d", &amp;n); //将最长的那个多项式的次数n进行变换得到tn while(tn &lt; 2 * n + 1) tn &lt;&lt;= 1; FWT_and(A, tn), FWT_and(B, tn); for(int i = 0; i &lt; tn; i++) A[i] = A[i] * B[i] % mod; FWT_and(A, tn, -1); return 0; }</code></pre>

页面列表

ITEM_HTML