计算系数
二项式定理
(ax+by)^k%p=sigma(i=0,k) c[i]*x^i*y^(k-i) c[i]=a^i*b^(k-i)*C(i,k)
要开long long虽然有模数,但在计算加法时可能会溢出使答案不正确
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const long long maxn=1007; 6 const long long mod=10007; 7 long long f[maxn+7][maxn+7],ans; 8 long long a,b,k,n,m; 9 void maketable(){ 10 for(long long i=0;i<=maxn;i++) 11 for(long long j=1;j<=maxn;j++) 12 f[i][j]=1; 13 for(long long i=2;i<=k;i++) 14 for(long long j=2;j<=i;j++) 15 f[i][j]=(f[i-1][j-1]+f[i-1][j])%mod; 16 } 17 long long quick(long long a,long long b,long long p){ 18 long long ans=1; 19 for( ;b;b>>=1,a=(a*a)%p){ 20 if(b&1==1){ 21 ans=(ans*a)%p; 22 } 23 } 24 return ans; 25 } 26 int main(){ 27 cin>>a>>b>>k>>n>>m; 28 maketable(); 29 ans=(quick(a,n,mod)*quick(b,m,mod)*f[k][n+1])%mod; 30 cout<<ans<<endl; 31 return 0; 32 }