Random Number Generator
Time limit2sMemory limit512 MB
Given how many values from 1 to N have been seen zero or one time, find the expected number of draws until every value appears at least twice.
- Level
Hard8 of 10
- Topics
- Probability, Dynamic programming, Math, Implementation
- Solved
- No attempts yet
Problem
There is a random number generator that returns an integer from to uniformly at random. Each time the generator returns a number, a friend writes it down. The friend stops the generator as soon as every integer from to has been recorded at least twice.
The generator has already returned numbers, and the -th returned number is . Since the friend has not stopped the generator yet, at least one integer from to has been returned fewer than twice.
Compute the expected number of additional requests needed until the friend stops the generator.
Input
The first line contains the number of test cases ().
The first line of each test case contains two integers and (, ). is the range of returned integers and is the number of integers already requested.
The second line of each test case contains integers (). This line is empty when .
It is guaranteed that not every integer has been returned twice yet. The sum of over all test cases does not exceed .
Output
For each test case, print the expected number of additional requests until the friend stops the generator, one per line.
An answer is accepted if its absolute or relative error is at most .
Hint
The expected remaining count depends only on how many integers have never appeared and how many have appeared exactly once, not on the full history.
When and nothing has been seen yet, more requests are always needed. When and has already appeared once, the answer is .