code:
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #define maxn 262146 7 #define mod 950009857 8 #define g 7 9 using namespace std; 10 typedef long long int64; 11 char ch; 12 int n,m,k,x,N,len,rev[maxn]; 13 int64 a[maxn],b[maxn],c[maxn],wwn[2][maxn],wn,w,t1,t2; 14 bool ok; 15 void read(int &x){ 16 for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1; 17 for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); 18 if (ok) x=-x; 19 } 20 void read(int64 &x){ 21 for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1; 22 for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); 23 if (ok) x=-x; 24 } 25 int re(int v){ 26 int t=0; 27 for (int i=0;i<len;i++) t<<=1,t|=v&1,v>>=1; 28 return t; 29 } 30 int64 ksm(int64 a,int64 b){ 31 int64 t=1; 32 for (;b;b>>=1){if (b&1) t=t*a%mod; a=a*a%mod;} 33 return t; 34 } 35 void ntt(int64 *a,int op){ 36 for (int i=0;i<N;i++) if (i<rev[i]) swap(a[i],a[rev[i]]); 37 for (int s=2;s<=N;s<<=1){ 38 wn=wwn[op][s]; 39 for (int i=0;i<N;i+=s){ 40 w=1; 41 for (int j=i;j<i+(s>>1);j++,w=w*wn%mod){ 42 t1=a[j],t2=w*a[j+(s>>1)]%mod; 43 a[j]=(t1+t2)%mod,a[j+(s>>1)]=((t1-t2)%mod+mod)%mod; 44 } 45 } 46 } 47 if (op==1){ 48 int64 x=ksm(N,mod-2); 49 for (int i=0;i<N;i++) a[i]=a[i]*x%mod; 50 } 51 } 52 int main(){ 53 read(n),read(m),read(k),N=1; 54 for (int i=0;i<n;i++) read(a[i]); 55 for (int i=1;i<=m;i++) read(x),b[x]++; 56 while (N<(n<<1)) len++,N<<=1; 57 for (int i=0;i<N;i++) rev[i]=re(i); 58 for (int i=1;i<=len;i++) wwn[0][1<<i]=ksm(g,(mod-1)/(1<<i)); 59 for (int i=1;i<=len;i++) wwn[1][1<<i]=ksm(wwn[0][1<<i],mod-2); 60 for (;k;k>>=1){ 61 ntt(b,0); 62 if (k&1){ 63 ntt(a,0); 64 for (int i=0;i<N;i++) a[i]=a[i]*b[i]%mod; 65 ntt(a,1); 66 for (int i=n;i<N;i++) a[i]=0; 67 } 68 for (int i=0;i<N;i++) b[i]=b[i]*b[i]%mod; 69 ntt(b,1); 70 for (int i=n;i<N;i++) b[i]=0; 71 } 72 for (int i=0;i<n;i++) printf("%lld ",a[i]); 73 puts(""); 74 return 0; 75 }