#abc270h. Ex - add 1
Ex - add 1
Score : points
问题描述
你得到一个包含 个非负整数的元组 ,其中 且 。
高桥有 个计数器。最初,所有计数器的值都是 。 他将重复以下操作,直到对任意 ,第 个计数器的值至少为 。
均匀随机选择 个计数器中的一个,并将其值设为 。(每次选择都独立于其他计数器。) 将 其他 计数器的值增加 。
计算并输出高桥重复该操作次数的期望值,结果对 取模(参见注释)。
以上为通义千问 qwen-max 翻译,仅供参考。
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 .
Sample Input 1
2
0 2
Sample Output 1
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.
Sample Input 2
5
0 1 3 10 1000000000000000000
Sample Output 2
874839568
update @ 2024/3/10 11:24:40