No.2461 All on One
Problem Statement
In the gacha of a certain social game, each time you roll it $1$ time, you obtain a "Rare Character" with probability $p$ by an independent draw. In parallel with this, rolling this gacha $K$ times guarantees that you obtain a "Rare Character". Suppose you keep rolling this gacha until you obtain a "Rare Character". Compute the expected value of the number of rolls.
Answer for $T$ test cases.
Input
Line $1$ contains an integer $T$. Then, $T$ test cases follow.
Each test case is given in the following format.
$p$ $K$
The input satisfies the following constraints.
- $T$ is an integer, $1 \le T \le 1000$
- $p$ has at least $1$ and at most $3$ digits in its fractional part (including trailing $0$s), $0 \le p \le 1$
- $K$ is an integer, $1 \le K \le 500$
Output
For each test case, print the real number that is the answer as a decimal on $1$ line. There is reference data created so that its absolute or relative error from the true value is at most $10^{-10}$; the value output by the submitted program is accepted if its absolute or relative error with respect to that data is at most $10^{-5}$. Print a newline at the end.
Sample
Sample 1
Input
4 0.5 2 1.0 100 0.7 5 0.002 500
Output
1.50000000000 1.00000000000 1.42510000000 316.24437257142
Explanation of test case 1. When you roll the gacha $1$ time, you obtain a "Rare Character" with probability $0.5$. If you did not obtain it, you are guaranteed to obtain a "Rare Character" on roll number $2$. The probability of rolling exactly $1$ time is $0.5$ and the probability of rolling $2$ times is $0.5$, so the desired expected value is $1 \times 0.5+2 \times 0.5=1.5$.
Explanation of test case 2. When you roll the gacha $1$ time, you obtain a "Rare Character" with probability $1$. There is no possibility of rolling the gacha $2$ or more times.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Nachia
Kazun