NTT的做法
ec好像是linux的机子,回头学下gdb调试
#include <cstdio>
#include <iostream>
#include <cmath>
typedef long long ll;
const int NR = 1 << 22, g = 3, gi = 332748118, mod = 998244353;
using namespace std;
int n, m, rev[NR];
ll a[NR], b[NR];
ll quikpow(ll a, ll k)
{
ll res = 1;
while (k > 0)
{
if (k&1)res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
void NTT(ll *a,int n,int type){
for(int i=0;i<=n;++i){
if(i<rev[i])swap(a[i],a[rev[i]]);
}
for(int i=1;i<n;i<<=1){
ll gn=quikpow(type?g:gi,(mod-1)/(i<<1));
for(int j=0;j<n;j+=(i<<1)){
ll g0=1;
for(int k=0;k<i;++k,g0=g0*gn%mod){
ll x=a[j+k],y=g0*a[i+j+k]%mod;
a[j+k]=(x+y)%mod;
a[i+j+k]=(x-y+mod)%mod;
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<=n;++i)scanf("%lld",a+i);
for(int i=0;i<=m;++i)scanf("%lld",b+i);
int len=1<<max((int)ceil(log2(n+m)),1);
for(int i=0;i<len;++i){
rev[i]=(rev[i>>1]>>1)|((i&1)<<(max((int)ceil(log2(n+m)),1)-1));
}
NTT(a,len,1);
NTT(b,len,1);
for(int i=0;i<=len;++i)a[i]=a[i]*b[i]%mod;
NTT(a,len,0);
ll inv=quikpow(len,mod-2);
for(int i=0;i<=n+m;++i)printf("%lld ",a[i]*inv%mod);
return 0;
}