Birthday Party
Time limit5sMemory limit256 MB
Each of N guests gives a present to a random other guest, and you must compute the probability that some k guests form a directed gift cycle.
- Level
Hard8 of 10
- Topics
- Combinatorics, Probability, Math
- Solved
- No attempts yet
Problem
people are invited to a birthday party. Each of them brings one present, and the person who receives that present is picked at random. Nobody gives a present to themselves, and each of the other people is equally likely to be picked. The choices are independent, so one guest can receive several presents while another receives none.
Call a gift cycle a set of distinct guests such that gives their present to , gives theirs to , and so on until gives theirs back to . Find the probability that at least one gift cycle of length appears.
Input
The first line contains the number of test cases . Each of the next lines contains two integers and separated by a space.
Output
For each test case, print the probability on its own line, rounded to exactly six digits after the decimal point. Print 1.000000 when the probability is , and 0.313470 when it is