atcoder#ABC242H. [ABC242Ex] Random Painting
[ABC242Ex] Random Painting
Score : points
Problem Statement
There are squares numbered to . Initially, all squares are painted white.
Additionally, there are balls numbered to in a box.
We repeat the procedure below until all squares are painted black.
- Pick up a ball from a box uniformly at random.
- Let be the index of the ball. Paint Squares black.
- Return the ball to the box.
Find the expected value of the number of times the procedure is done, modulo (see Notes).
Notes
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , it can be proved that there uniquely exists an integer such that and . You should find this .
Constraints
- For every square , there is an integer such that .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sought expected value modulo .
3 3
1 1
1 2
2 3
499122180
The sought expected value is .
We have , so should be printed.
13 10
3 5
5 9
3 12
1 13
9 11
12 13
2 4
9 12
9 11
7 11
10
100 11
22 43
84 93
12 71
49 56
8 11
1 61
13 80
26 83
23 100
80 85
9 89
499122193