什么时候NOIP也要出二项式定理了?
二项式定理+逆元。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mod 10007 using namespace std; long long a,b,k,n,m,table[1050]; void get_table() { table[1]=1; for (long long i=2;i<=k;i++) table[i]=(table[i-1]*i)%mod; return; } long long f_pow(long long x,long long y) { long long base=x,ret=1; while (y) { if (y&1) ret=(ret*base)%mod; base=(base*base)%mod; y>>=1; } return ret%mod; } int main() { scanf("%lld%lld%lld%lld%lld",&a,&b,&k,&n,&m); if (k==0) {printf("1 ");return 0;} long long ans1,ans2,ans3; get_table(); ans1=table[k]*f_pow(table[n],mod-2)%mod; ans1=ans1*f_pow(table[k-n],mod-2)%mod; ans2=f_pow(a,n)%mod;ans3=f_pow(b,m)%mod; printf("%lld ",((ans1*ans2)%mod*ans3)%mod); return 0; }