TopCoder problem "LuckyFives" used in TCHS SRM 25 (Division I Level Two)



Problem Statement

    Some people think five is a lucky number. They roll several dice, and if they get five on strictly more than one fifth of the dice, they believe it will be a lucky day.



Given an int dice, the number of dice rolled, and an int sides, the number of sides on each die, return the probability of the day being lucky. For a die with N sides, the probability of rolling a five is 1/N.
 

Definition

    
Class:LuckyFives
Method:probability
Parameters:int, int
Returns:double
Method signature:double probability(int dice, int sides)
(be sure your method is public)
    
 

Notes

-Your return value must have an absolute or relative error less than 1e-9.
 

Constraints

-dice will be between 1 and 20, inclusive.
-sides will be between 5 and 10, inclusive.
 

Examples

0)
    
1
6
Returns: 0.16666666666666666
If you roll one six-sided die, you will get five with a probability of 1/6.
1)
    
5
6
Returns: 0.19624485596707822
Here you roll five six-sided dice, and you need at least two fives.
2)
    
4
10
Returns: 0.3439
3)
    
20
10
Returns: 0.04317449528446337

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6586

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10077&pm=6586

Writer:

Vedensky

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math