You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 2010, mod = 100003; // 因为式子中出现a+c所以N要开两倍
int fact[N], infact[N]; // 阶乘与阶乘的逆元
// 快速幂模板
int qmi(int a, int k) {
int res = 1;
while (k) {
if (k & 1) res = res * a % mod;
a = a * a % mod;
k >>= 1;
}
return res;
}
// 组合数
int C(int a, int b) {
if (a < b) return 0;
return fact[a] % mod * infact[a - b] % mod * infact[b] % mod;
}
// 排列数
int P(int a, int b) {
if (a < b) return 0;
return fact[a] % mod * infact[a - b] % mod;
}
signed main() {
// 组合数公式II
// 预处理出阶乘和阶乘的逆元
fact[0] = infact[0] = 1; // 0的阶乘是1,这是人为的规定。 1/1也是1infact[0]也是1
for (int i = 1; i < N; i++) {
fact[i] = fact[i - 1] * i % mod; // 阶乘
infact[i] = infact[i - 1] * qmi(i, mod - 2) % mod; // 因为100003是质数可以用费马小定理求出阶乘的逆元
}
int a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
int res = 0;
for (int i = 0; i <= k; i++) // 在上面的矩阵中放i个但要注意C(a,b),P(a,b)中a>=b,这里处理的也非常巧妙,
// 没有在计算时进行特判而是在实现C函数、P函数时进行了特判if(a<b) return 0;
res = (res + C(b, i) * P(a, i) % mod * C(d, k - i) % mod * P(a + c - i, k - i)) % mod;
printf("%lld\n", res);
}