91752024-02-16 20:36:52111Séta Alatti Területcpp17Wrong answer 0/100231ms67568 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007

int pow_mod(int x, int p) {
	int r = 1;
	while (p > 0) {
		if (p % 2 == 1) {
			r *= x;
			r %= MOD;
		}
		p /= 2;
		x *= x;
		x %= MOD;
	}
	return r;
}

int inv_mod(int x) {
	return pow_mod(x, MOD - 2);
}

int fac_mod(int x) {
	static vector<int> v = { 1 };
	while (v.size() - 1 < x) {
		v.push_back(v.back() * v.size() % MOD);
	}
	return v[x];
}

int inv_fac_mod(int x) {
	static vector<int> v = { 1 };
	while (v.size() - 1 < x) {
		v.push_back(v.back() * inv_mod(v.size()) % MOD);
	}
	return v[x];
}

int bin_mod(int n, int k) {
	if (k < 0 || k > n) {
		return 0;
	}
	return fac_mod(n) * inv_fac_mod(n - k) % MOD * inv_fac_mod(k) % MOD;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, M, P, R;
	cin >> N >> M >> P >> R;
	int r = N / P, c = M / P;
	int ans = bin_mod(N + M, N) - bin_mod(r + c, r) + MOD;
	ans %= MOD;
	ans *= inv_mod(P);
	ans %= MOD;
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1824 KiB
2Accepted3ms2016 KiB
subtask20/16
3Wrong answer3ms2232 KiB
4Wrong answer3ms2464 KiB
5Wrong answer3ms2652 KiB
6Wrong answer2ms2740 KiB
7Wrong answer3ms2864 KiB
8Wrong answer2ms2956 KiB
9Accepted2ms3060 KiB
10Wrong answer2ms2948 KiB
11Wrong answer2ms2948 KiB
12Wrong answer3ms3080 KiB
13Wrong answer2ms3168 KiB
subtask30/21
14Wrong answer2ms3164 KiB
15Wrong answer2ms3264 KiB
16Wrong answer3ms3392 KiB
17Wrong answer3ms3272 KiB
18Wrong answer2ms3280 KiB
19Wrong answer3ms3404 KiB
20Wrong answer3ms3280 KiB
21Wrong answer2ms3272 KiB
22Wrong answer2ms3276 KiB
subtask40/25
23Accepted24ms9820 KiB
24Wrong answer209ms52320 KiB
25Accepted209ms52324 KiB
26Wrong answer24ms9820 KiB
27Wrong answer209ms52312 KiB
28Wrong answer221ms52440 KiB
subtask50/38
29Wrong answer209ms43704 KiB
30Wrong answer203ms43692 KiB
31Wrong answer231ms66812 KiB
32Wrong answer231ms66952 KiB
33Wrong answer222ms67044 KiB
34Wrong answer223ms67112 KiB
35Wrong answer221ms67116 KiB
36Wrong answer231ms67320 KiB
37Wrong answer224ms67568 KiB