1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include<bits/stdc++.h> using namespace std;
const int maxn = 10000005; const int mod = 1e9 + 7;
inline int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; b >>= 1; } return ret; } int inv[maxn];
int n, ans; int p, q, p2, q2; int invp2, invq2; int pa, pb, qa, qb; int powp, powq; int powp2, powq2; int sq; int C;
int main() { scanf("%d", &n); scanf("%d%d", &pa, &pb); p = 1ll * pa * qpow(pb, mod - 2) % mod; p2 = (1 - p + mod) % mod; scanf("%d%d", &qa, &qb); q = 1ll * qa * qpow(qb, mod - 2) % mod; q2 = (1 - q + mod) % mod; if (p == 1) return printf("%d", (1 - qpow(q, n) + mod) % mod), 0; inv[1] = 1; for (int i = 2; i <= n; ++i) { inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; } C = 1; powp = 1, powq = 1; powp2 = qpow(p2, n), powq2 = qpow(q2, n); invp2 = qpow(p2, mod - 2), invq2 = qpow(q2, mod - 2); int tp = 1ll * powp * powp2 % mod, tq = 1ll * powq * powq2 % mod; int mp = 1ll * p * invp2 % mod, mq = 1ll * q * invq2 % mod; sq = powq2; for (int i = 1; i <= n; ++i) { C = 1ll * C * (n - i + 1) % mod * inv[i] % mod; tp = 1ll * tp * mp % mod; tq = 1ll * tq * mq % mod; ans = (ans + 1ll * tp % mod * sq % mod * C) % mod; sq = (sq + 1ll * tq % mod * C) % mod; } printf("%d", ans); return 0; }
|