1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| #include<bits/stdc++.h> #define int long long #define double long double using namespace std; const int max_n=2000006,mod=1000003; inline int read(){ int x=0;bool w=0;char c=getchar(); while(c<'0' || c>'9') w|=c=='-',c=getchar(); while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return w?-x:x; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); } inline int mi(int a,int p=mod-2){ int res=1; while(p){ if(p&1) res*=a,res%=mod; a*=a,a%=mod,p>>=1; } return res; } namespace DXS{ struct com{ double a,b; com(double x=0,double y=0){a=x,b=y;} com operator + (const com b) const{ com a=*this,res; res.a=a.a+b.a,res.b=a.b+b.b; return res; } com operator - (const com b) const{ com a=*this,res; res.a=a.a-b.a,res.b=a.b-b.b; return res; } com operator * (const com b) const{ com a=*this,res; res.a=a.a*b.a-a.b*b.b, res.b=a.a*b.b+a.b*b.a; return res; } }; int rev[max_n*8]; const double Pi=acos(-1.0); inline void FFT(com *g,int n,bool op){ for(register int i=0;i<n;++i) if(i<rev[i]) swap(g[i],g[rev[i]]); for(register int mid=1;mid<n;mid<<=1){ com omega(cos(Pi/mid),sin(Pi/mid)*(op?1:-1)); for(register int i=0;i<n;i+=(mid<<1)){ com w(1,0); for(register int j=0;j<mid;++j,w=w*omega){ com x=g[i+j],y=w*g[i+j+mid]; g[i+j]=x+y, g[i+j+mid]=x-y; } } } } const int K=32768,S=K*K; inline void mulMTT(int *f,int *g,int n,int m,int mod){ static com P[max_n],Q[max_n],R[max_n]; for(register int i=0;i<n;++i){ P[i].a=f[i]/K, P[i].b=f[i]%K; R[i].a=f[i]/K, R[i].b=-f[i]%K; } for(register int i=0;i<m;++i){ Q[i].a=g[i]/K, Q[i].b=g[i]%K; } int len=1; while(len<=n+m) len<<=1; for(register int i=0;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?len>>1:0); FFT(P,len,1),FFT(Q,len,1),FFT(R,len,1); for(register int i=0;i<len;++i){ Q[i].a/=len, Q[i].b/=len; } for(register int i=0;i<len;++i){ P[i]=P[i]*Q[i], R[i]=R[i]*Q[i]; } FFT(P,len,0),FFT(R,len,0); for(register int i=0,a1b1=0,a1b2=0,a2b1=0,a2b2=0;i<len;++i){ a1b1=(int)floor((P[i].a+R[i].a)/2+0.5)%mod, a1b2=(int)floor((P[i].b+R[i].b)/2+0.5)%mod, a2b1=((int)floor(P[i].b+0.5)-a1b2)%mod, a2b2=((int)floor(R[i].a+0.5)-a1b1)%mod; f[i]=(a1b1*S%mod+(a1b2+a2b1)%mod*K%mod+a2b2)%mod; f[i]=(f[i]%mod+mod)%mod; } } }
int n,A,B,c,ans; int fac[max_n*2],inv[max_n*2]; int f[max_n*8],g[max_n*8];
inline int C(int n,int m){ if(n<0 || m<0 || n<m) return 0; return fac[n]*inv[m]%mod*inv[n-m]%mod; }
signed main(){ n=read(),A=read(),B=read(),c=read(); fac[0]=inv[0]=1; for(register int i=1;i<=(n<<1);++i) fac[i]=fac[i-1]*i%mod; inv[n<<1]=mi(fac[n<<1]); for(register int i=(n<<1)-1;i;--i) inv[i]=inv[i+1]*(i+1)%mod; for(register int i=1;i<=n;++i){ int x=read(); if(i==1) continue; ans=(ans+C(2*n-i-2,n-2)*mi(A,n-1)%mod*mi(B,n-i)%mod*x%mod)%mod; } for(register int i=1;i<=n;++i){ int x=read(); if(i==1) continue; ans=(ans+C(2*n-i-2,n-2)*mi(A,n-i)%mod*mi(B,n-1)%mod*x%mod)%mod; } for(register int i=2;i<=n;++i){ f[i]=mi(A,n-i)*inv[n-i]%mod, g[i]=mi(B,n-i)*inv[n-i]%mod; } DXS::mulMTT(f,g,n+1,n+1,mod); for(register int i=4;i<=(n<<1);++i) ans=(ans+c*fac[2*n-i]%mod*f[i]%mod)%mod; write(ans); return 0; }
|