# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19424 | Qwaz | Ω (kriii4_P3) | C++14 | 0 ms | 1084 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
typedef long long ll;
const int MOD = 1000000007, MAX = 110;;
ll modpow(ll a, ll x) {
ll ret = 1;
a = a % MOD;
while (x) {
if (x & 1) ret = ret * a % MOD;
a = a * a % MOD;
x >>= 1;
}
return ret;
}
int p, q, n, k;
ll coeff[MAX], constant[MAX], val[MAX];
int main() {
scanf("%d%d%d%d", &p, &q, &n, &k);
if (k == 0) puts("0");
else if (k == n) puts("1");
else {
ll x = q * modpow(p, MOD-2) % MOD;
ll y = 1 - x;
if (y < 0) y += MOD;
coeff[n] = 0;
constant[n] = 1;
for (int i = n-1; i > 0; i--) {
ll div = 1 - y * coeff[i+1];
div %= MOD;
if (div < 0) div += MOD;
div = modpow(div, MOD-2);
coeff[i] = x * div % MOD;
constant[i] = (y * constant[i+1] % MOD) * div % MOD;
}
val[0] = 0;
val[1] = constant[1];
for (int i = 2; i < n; i++) {
val[i] = (coeff[i] * val[i-1] + constant[i]) % MOD;
}
printf("%lld\n", val[k]);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |