【题目链接】
https://www.luogu.org/problemnew/show/P1313
【算法】
二项式定理
【代码】
#include<bits/stdc++.h> using namespace std; const int P = 10007; int a,b,k,n,m,ans; int fac[1010],inv[1010]; inline int power(int a,int n) { int res = 1,b = a; while (n) { if (n & 1) res = 1ll * res * b % P; b = 1ll * b * b % P; n >>= 1; } return res; } inline void init() { int i; fac[0] = 1; for (i = 1; i <= k; i++) fac[i] = 1ll * fac[i-1] * i % P; inv[k] = power(fac[k],P-2); for (i = k - 1; i >= 1; i--) inv[i] = 1ll * inv[i+1] * (i + 1) % P; } inline int C(int n,int m) { return 1ll * fac[n] * inv[m] % P * inv[n-m] % P; } int main() { scanf("%d%d%d%d%d",&a,&b,&k,&n,&m); init(); ans = 1ll * C(k,n) * power(a,n) % P * power(b,m) % P; printf("%d\n",ans); return 0; }
原文:https://www.cnblogs.com/evenbao/p/9291135.html