Preparing NOJ

Beat the Monster

5000ms 131072K

Description:

LYA is playing a RPG game and he needs to kill a monster. The monster's health is $$$h$$$, LYA's attack is $$$a$$$ and the monster's defence is $$$d$$$. So every time the monster's health will decrease $$$a - d$$$. And each time LYA has a $$$\frac{p}{q}$$$ probability to trigger a critical hit, which will double LYA's attack, and the monster's health will decrease $$$2a - d$$$.
Since the monster has a huge health, he wants you to help him find out the expectation of the time he need to kill the monster.

Input:

One line with 5 space-separated integers $$$h, a, d, p, q (1 \le h \le 5 \cdot 10^7, 0 \le d \lt a \le 10^5, 1 \le p \le q \le 10^7)$$$.

Output:

Output answer in the fraction modulo $$$10^7 + 19$$$, that is, if the answer is $$$\frac{P}{Q}$$$, you should output $$$P \cdot Q^{-1}$$$ modulo $$$10^7+19$$$, where $$$Q^{-1}$$$ denotes the multiplicative inverse of $$$Q$$$ modulo $$$10^7+19$$$.

Sample Input:

15 5 0 1 2

Sample Output:

2500007

Info

NOJ

Provider NOJ

Code NOJ2379

Tags

Submitted 122

Passed 40

AC Rate 32.79%

Date 08/13/2019 00:47:12

Related

Nothing Yet