atcoder#ABC270H. [ABC270Ex] add 1
[ABC270Ex] add 1
Score : points
Problem Statement
You are given a tuple of non-negative integers such that and .
Takahashi has counters. Initially, the values of all counters are . He will repeat the following operation until, for every , the value of the -th counter is at least .
Choose one of the counters uniformly at random and set its value to . (Each choice is independent of others.) Increase the values of the other counters by .
Print the expected value of the number of times Takahashi repeats the operation, modulo (see Notes).
Notes
It can be proved that the sought expected value is always finite and rational. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , one can prove that there is a unique integer such that and . Find this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of the number of times Takahashi repeats the operation, modulo .
2
0 2
6
Let denote the value of the -th counter.
Here is one possible progression of the process.
- Set the value of the -st counter to , and then increase the value of the other counter by . Now, .
- Set the value of the -nd counter to , and then increase the value of the other counter by . Now, .
- Set the value of the -st counter to , and then increase the value of the other counter by . Now, .
- Set the value of the -st counter to , and then increase the value of the other counter by . Now, .
In this case, the operation is performed four times.
The probabilities that the process ends after exactly operation(s) are $0,\frac{1}{4}, \frac{1}{8}, \frac{1}{8}, \frac{3}{32},\ldots$, respectively, so the sought expected value is $2\times\frac{1}{4}+3\times\frac{1}{8}+4\times\frac{1}{8}+5\times\frac{3}{32}+\dots=6$. Thus, should be printed.
5
0 1 3 10 1000000000000000000
874839568