High-Roller Rory
Submit solution
Points:
1
Time limit:
1.0s
Memory limit:
256M
Author:
Problem type
Allowed languages
C++, Java, Python
As RSP's biggest gambling addict, Rory is playing a game of chance. His score starts at zero, and he has a fair -sided die with faces numbered from
to
. He repeatedly rolls the die:
- If the number is between
and
, he adds that number to his score.
- If the number is
, he immediately loses.
Rory wins the game if his score reaches at least . What is the probability that he wins the game?
Input
The first line of the input contains two integers and
, the number of sides on the die, and the score that Rory needs to win.
Output
Output the probability that Rory wins the game, between 0.0 and 1.0, correct to exactly 6 decimal places.
Example
Input 1
3 2
Output 1
0.555556
Rory has a -sided die, and he needs to get a score of at least
to win.
On the first roll:
- He has a
of getting
point (by rolling a
).
- He has a
chance of winning instantly (by rolling a
).
- He has a
chance of losing instantly (by rolling a
).
If there is a second roll, he is guaranteed to have exactly point, so:
- He has a
chance of winning instantly (by rolling a
or
).
- He has a
chance of losing instantly (by rolling a
).
Overall, he has a chance of winning, and a
chance of losing.

Input 2
2 4
Output 2
0.062500
Input 3
67 420
Output 3
0.820550
Comments