#abc352g. G - Socks 3
G - Socks 3
Score: points
问题陈述
高桥在他的抽屉里有各种颜色的袜子。袜子的颜色由整数 到 表示,颜色 的袜子有 只。
他即将通过执行以下操作来选择今天要穿哪双袜子:
- 继续从抽屉中随机抽取一只袜子,每次抽取的概率相等,直到他能够从已经抽取的袜子中配成一对同色的袜子。一旦抽取了一只袜子,它将不会被放回抽屉。
找出他必须从抽屉中抽取袜子的次数的期望值,模 。
寻找模 的期望值意味着什么?可以证明所求的期望值总是有理数。此外,这个问题的约束条件保证如果期望值表示为不可约分数 ,那么 不能被 整除。在这里,存在一个唯一的整数 ,介于 和 (包括 和 ),使得 。找出这个 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Takahashi has various colors of socks in his chest of drawers. The colors of the socks are represented by integers from to , and there are socks of color .
He is about to choose which socks to wear today by performing the following operation:
- Continue to randomly draw one sock at a time from the chest, with equal probability, until he can make a pair of socks of the same color from those he has already drawn. Once a sock is drawn, it will not be returned to the chest.
Find the expected value, modulo , of the number of times he has to draw a sock from the chest.
What does it mean to find the expected value modulo ? It can be proved that the sought expected value is always rational. Furthermore, the constraints of this problem guarantee that if the expected value is expressed as an irreducible fraction , then is not divisible by . Here, there exists a unique integer between and , inclusive, such that . Find this .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2
2 2
Sample Output 1
665496238
For example, the operation could be performed as follows:
- Draw a sock of color from the chest. There remains one sock of color and two socks of color in the chest.
- Draw a sock of color from the chest. There remains one sock each of colors and in the chest.
- Draw a sock of color from the chest. The socks drawn so far are two of color and one of color , allowing a pair of color socks to be made, thus ending the operation.
In this example, Takahashi draws a sock from the chest three times.
The expected number of times Takahashi draws a sock from the chest is with probability and with probability , so the expected value is $3\times \frac{2}{3} + 2\times \frac{1}{3} = \frac{8}{3} \equiv 665496238 \pmod {998244353}$.
Sample Input 2
1
352
Sample Output 2
2
Sample Input 3
6
1796 905 2768 253 2713 1448
Sample Output 3
887165507