#abc310g. G - Takahashi And Pass-The-Ball Game
G - Takahashi And Pass-The-Ball Game
Score : points
问题陈述
设有 名高桥。
第 名高桥拥有整数 和 个球。
将从包括 1 到 的整数中均匀随机选择一个整数 ,他们将重复以下操作 次:
- 对于每一个 ,第 名高桥将其所有的球都给到第 名高桥。
注意所有 名高桥同时执行此操作。
对于每一名 ,求在操作结束后第 名高桥拥有的球数的期望值,结果对 取模。
如何求解模 下的期望值? 可以证明所求概率始终是一个有理数。此外,本问题的约束条件保证了如果该概率表示为不可约分数 ,则 不会被 整除。此时存在一个唯一的满足 的整数 ,使得 ,请报告这个 值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are Takahashi.
The -th Takahashi has an integer and balls.
An integer between and , inclusive, will be chosen uniformly at random, and they will repeat the following operation times.
- For every , the -th Takahashi gives all his balls to the -th Takahashi.
Beware that all Takahashi simultaneously perform this operation.
For each , find the expected value, modulo , of the number of balls the -th Takahashi has at the end of the operations.
How to find a expected value modulo It can be proved that the sought probability is always a rational number. Additionally, the constraints of this problem guarantee that if the sought probability is represented as an irreducible fraction , then is not divisible by . Here, there is a unique such that , so report this .
Constraints
- is not a multiple of .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of the number of balls the -th Takahashi has at the end of the operations for , separated by spaces, in a single line.
Sample Input 1
5 2
3 1 4 1 5
1 1 2 3 5
Sample Output 1
3 0 499122179 499122178 5
During two operations, the five Takahashi have the following number of balls.
If is chosen, the five Takahashi have balls.
If is chosen, the five Takahashi have balls.
Thus, the sought expected values are . Print these values modulo , that is, , separated by spaces.
Sample Input 2
3 1000
1 1 1
1 10 100
Sample Output 2
111 0 0
After one or more operations, the first Takahashi gets all balls.
Sample Input 3
16 1000007
16 12 6 12 1 8 14 14 5 7 6 5 9 6 10 9
719092922 77021920 539975779 254719514 967592487 476893866 368936979 465399362 342544824 540338192 42663741 165480608 616996494 16552706 590788849 221462860
Sample Output 3
817852305 0 0 0 711863206 253280203 896552049 935714838 409506220 592088114 0 413190742 0 363914270 0 14254803
Sample Input 4
24 100000000007
19 10 19 15 1 20 13 15 8 23 22 16 19 22 2 20 12 19 17 20 16 8 23 6
944071276 364842194 5376942 671161415 477159272 339665353 176192797 2729865 676292280 249875565 259803120 103398285 466932147 775082441 720192643 535473742 263795756 898670859 476980306 12045411 620291602 593937486 761132791 746546443
Sample Output 4
918566373 436241503 0 0 0 455245534 0 356196743 0 906000633 0 268983266 21918337 0 733763572 173816039 754920403 0 273067118 205350062 0 566217111 80141532 0
update @ 2024/3/10 08:49:29