版权声明:作为一个蒟蒻,转载时请通知我这个蒟蒻 https://blog.csdn.net/zyszlb2003/article/details/89608029
欢迎大家访问我的老师的OJ———caioj.cn
题面描述
思路
根据组合计数中的二项式定理,有
则 的系数应为 ,因为 ,我们可以先求出 , ,因为这里的模数是质数 ,
所以我们并不用 求逆元,而是直接快速幂求出 ,即 的乘法逆元(由费马小定理可以得知)。
剩余的 ,快速幂即可。
AC code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define ll long long
using namespace std;
const int mod=10007;
const int N=1e4+10;
ll c[N];int tot;
inline ll pow_mod(ll a,ll b)
{
ll ans=1;a%=mod;
while(b)
{
if(b&1)ans=ans*a%mod;
b>>=1;a=a*a%mod;
}
return ans;
}
inline ll get(ll n)
{
if(tot>=n)return c[n];
while(tot<=n)
{
++tot;
c[tot]=c[tot-1]*tot%mod;
}
return c[n];
}
int main()
{
ll a,b,k,n,m;scanf("%lld%lld%lld%lld%lld",&a,&b,&k,&n,&m);
tot=0;c[0]=1;
ll x=get(k),y=get(n)*get(m);//y=get(n)+get(k-n);
y=pow_mod(y,mod-2);
ll s=x*y%mod;
x=pow_mod(a,n),y=pow_mod(b,m);
s=s*x*y%mod;
printf("%lld\n",s);
return 0;
}