#abc331g. G - Collect Them All
G - Collect Them All
Score : points
问题描述
在一个盒子里有 张卡片。每张卡片上都写有一个整数,这个整数介于 和 (包含)之间。对于每个 ,有 张卡片上写着数字 。
从一本空白笔记本开始,你重复以下操作:
- 随机从盒子里抽出一张卡片。将卡片上的整数记在笔记本上,然后将卡片放回盒子。
求出执行该操作直至笔记本中至少记录过一次从 到 的所有整数的期望次数,结果对 取模。
如何求解模 下的期望值 本问题所求的期望值可以被证明始终是一个有理数。此外,本题的约束条件保证了当期望值表示为不可约分数 时,分母 不会是 的倍数。因此,存在一个唯一的 ,使得 。请输出这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are cards in a box. Each card has an integer written on it, which is between and , inclusive. For each , there are cards with the number written on them.
Starting with an empty notebook, you repeat the following operation:
- Randomly draw one card from the box. Write the integer on the card in the notebook, then return the card to the box.
Find the expected value, modulo , of the number of times the operation is performed until the notebook has all integers from to written at least once.
How to find an expected value modulo The expected value sought in this problem can be proven to always be a rational number. Furthermore, the constraints of this problem guarantee that when the expected value is expressed as an irreducible fraction , the denominator is not divisible by . Then, there is a unique such that . Print 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
1 1
Sample Output 1
3
The series of operations may proceed as follows:
- You draw a card with written on it. The notebook now has one written in it.
- You again draw a card with written on it. The notebook now has two s written in it.
- You draw a card with written on it. The notebook now has two s and one written in it.
The sought expected value is $2\times\frac{1}{2}+3\times\frac{1}{4}+4\times\frac{1}{8}+\ldots=3$.
Sample Input 2
5 2
4 1
Sample Output 2
748683270
The expected value is , whose representation modulo is .
Sample Input 3
50 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output 3
244742906
The expected value is $\frac{13943237577224054960759}{61980890084919934128}$.
Sample Input 4
74070 15
1 2 3 11 22 33 111 222 333 1111 2222 3333 11111 22222 33333
Sample Output 4
918012973
update @ 2024/3/10 01:16:32