二项式定理
(
a
+
b
)
n
=
∑
k
=
0
n
(
n
k
)
a
k
b
n
−
k
(a+b)^n=\sum\limits_{k=0}^{n}\dbinom{n}{k}a^k b^{n-k}
(
a
+
b
)
n
=
k
=
0
∑
n
(
k
n
)
a
k
b
n
−
k
证明:
(a
+
b
)
n
=
(
a
+
b
)
(
a
+
b
)
⋯
(
a
+
b
)
⏟
n
个
(
a
+
b
)
(a+b)^n=\begin{matrix}\underbrace{(a+b)(a+b)\cdots(a+b)}\\n个(a+b)\end{matrix}
(
a
+
b
)
n
=
(
a
+
b
)
(
a
+
b
)
⋯
(
a
+
b
)
n
个
(
a
+
b
)
如果现在要得到
ak
b
n
−
k
a^k b^{n-k}
a
k
b
n
−
k
,那么只需要在这
nn
n
个
(a
+
b
)
(a+b)
(
a
+
b
)
中选
kk
k
个取
aa
a
,剩下
(n
−
k
)
(n-k)
(
n
−
k
)
个自动就选
bb
b
了。所以这一项就有
(n
k
)
\dbinom{n}{k}
(
k
n
)
个,值就是
(n
k
)
a
k
b
n
−
k
\dbinom{n}{k}a^k b^{n-k}
(
k
n
)
a
k
b
n
−
k
。对于每一项都是这样。
证毕。
Code
\text{Code}
Code
//18 = 9 + 9 = 18.
#include <iostream>
#include <cstdio>
#define Debug(x) cout << #x << "=" << x << endl
using namespace std;
const int MAXN = 1005;
const int MOD = 10007;
int qpow(int a, int b)
{
int base = a, ans = 1;
while (b)
{
if (b & 1)
{
ans = ans * base % MOD;
}
base = base * base % MOD;
b >>= 1;
}
return ans;
}
int inv(int a)
{
return qpow(a, MOD - 2);
}
int fac[MAXN], inv_fac[MAXN];
void init(int n)
{
fac[0] = 1;
for (int i = 1; i <= n; i++)
{
fac[i] = fac[i - 1] * i % MOD;
}
inv_fac[n] = inv(fac[n]);
for (int i = n - 1; i >= 1; i--)
{
inv_fac[i] = inv_fac[i + 1] * (i + 1) % MOD;
}
}
int C(int n, int m)
{
return fac[n] * inv_fac[n - m] % MOD * inv_fac[m] % MOD;
}
int main()
{
int a, b, k, n, m;
scanf("%d%d%d%d%d", &a, &b, &k, &n, &m);
a %= MOD, b %= MOD;
init(k);
printf("%d\n", C(k, n) * qpow(a, n) % MOD * qpow(b, m) % MOD);
return 0;
}