Problem K
Great Geek Game-show 3000!
The rules of the game are the following: There is a stage with $N$ boxes, each containing the name of one of the $N$ contestants, and such that each contestant has their name in exactly one box. The contestants enter the stage one at a time, and each one is allowed to peek inside $K$ of the boxes. If they find their own name inside one of these boxes they can get off the stage, and the game continues with the next contestant. If all contestants find their own name, everyone wins. But if one contestant fails to find theirs, everyone loses. After the game has begun, no communication between the contestants is allowed. However you are all allowed to agree upon a strategy before the game begins, and this is where you explain to all the others that the algorithm of everyone choosing $K$ boxes at random is a very bad one, since it gives a chance of winning only equal to $\left(\frac{K}{N}\right)^ N$. Instead you suggest the following algorithm:
Assign to each player and each box a unique number in the range $1, \dots , N$. Then each player starts with opening the box with the same number as themselves. The next box the player opens is the box whose number is found inside the first box, then the box whose number is found inside the second box, and so on. The process goes on until the player has opened $K$ boxes, or found their own number.
Now to bring home your point of how superior your algorithm is, you will need to calculate the exact odds of winning if all the contestants follow your directions. Unfortunately, this is the only thing you haven’t figured out yet
Input
One line with the following integers:
$1 \leq N \leq 10000000$ –
the number of contestants.
$1 \leq K \leq N$ – the
number of boxes each contestant may check.
Output
The chances you have of winning if everyone follows your algorithm. The answer should be accurate to an absolute or relative error of at most $10^{-6}$.
Sample Input 1 | Sample Output 1 |
---|---|
4 2 |
0.416667 |
Sample Input 2 | Sample Output 2 |
---|---|
6 5 |
0.833333 |
Sample Input 3 | Sample Output 3 |
---|---|
137 42 |
0.029351 |
Sample Input 4 | Sample Output 4 |
---|---|
2 1 |
0.500000 |