Submission #19424

#TimeUsernameProblemLanguageResultExecution timeMemory
19424QwazΩ (kriii4_P3)C++14
100 / 100
0 ms1084 KiB
#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 timeMemoryGrader output
Fetching results...