91742024-02-16 20:35:32111Séta Alatti Területcpp17Wrong answer 0/100222ms67020 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);
	ans *= inv_mod(P);
	ans %= MOD;
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1960 KiB
2Accepted3ms2084 KiB
subtask20/16
3Wrong answer3ms2296 KiB
4Wrong answer3ms2532 KiB
5Wrong answer3ms2672 KiB
6Wrong answer3ms2644 KiB
7Wrong answer3ms2908 KiB
8Wrong answer3ms2856 KiB
9Accepted2ms2740 KiB
10Wrong answer3ms2876 KiB
11Wrong answer3ms2952 KiB
12Wrong answer3ms3092 KiB
13Wrong answer3ms3096 KiB
subtask30/21
14Wrong answer3ms3208 KiB
15Wrong answer2ms3116 KiB
16Wrong answer3ms3124 KiB
17Wrong answer3ms3136 KiB
18Wrong answer3ms3140 KiB
19Wrong answer3ms3424 KiB
20Wrong answer3ms3408 KiB
21Wrong answer3ms3420 KiB
22Wrong answer3ms3420 KiB
subtask40/25
23Accepted24ms9968 KiB
24Wrong answer209ms52472 KiB
25Accepted209ms52724 KiB
26Wrong answer25ms10312 KiB
27Wrong answer209ms52856 KiB
28Wrong answer209ms52656 KiB
subtask50/38
29Wrong answer202ms43840 KiB
30Wrong answer202ms43844 KiB
31Wrong answer221ms66836 KiB
32Wrong answer221ms66844 KiB
33Wrong answer221ms66844 KiB
34Wrong answer221ms66916 KiB
35Wrong answer221ms67020 KiB
36Wrong answer221ms66892 KiB
37Wrong answer222ms66896 KiB