#abc326e. E - Revenge of "The Salary of AtCoder Inc."
E - Revenge of "The Salary of AtCoder Inc."
Score : points
问题描述
Aoki 是 AtCoder Inc. 的一名员工,本月的工资由一个整数 和长度为 的序列 如下确定:
首先,他获得了一个 面骰子(投掷一次可显示从 到 的整数,每个数字出现的概率相等),并初始化变量 。
然后,重复执行以下步骤直至结束:
- 投掷骰子一次,得到的结果记为 。
- 若 ,则支付给他 日元,并令 。
- 否则,终止该过程。
Aoki 本月的工资即通过此过程累计支付的总额。
求 Aoki 本月工资的期望值,结果对 取模。
如何求取模 下的期望值:
可以证明本问题中所求期望值始终是一个有理数。同时,本题的约束条件保证了若将所求期望值表示为简化分数 ,则 不会被 整除。此时存在唯一的一个满足 的整数 ,使得 。请输出这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Aoki, an employee at AtCoder Inc., has his salary for this month determined by an integer and a sequence of length as follows.
First, he is given an -sided die (dice) that shows the integers from to with equal probability, and a variable .
Then, the following steps are repeated until terminated.
- Roll the die once and let be the result.
- If , pay him yen and let .
- Otherwise, terminate the process.
Aoki's salary for this month is the total amount paid through this process.
Find the expected value of Aoki's salary this month, modulo .
How to find an expected value modulo It can be proved that the sought expected value in this problem is always a rational number. Also, the constraints of this problem guarantee that if the sought expected value is expressed as a reduced fraction , then is not divisible by . Here, there is exactly one such that . Print this .
Constraints
- All inputs are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
3 2 6
Sample Output 1
776412280
Here is an example of how the process goes.
- Initially, .
- Roll the die once, and it shows . Since , pay him yen and let .
- Roll the die once, and it shows . Since , pay him yen and let .
- Roll the die once, and it shows . Since , terminate the process.
In this case, his salary for this month is yen.
It can be calculated that the expected value of his salary this month is yen, whose representation modulo is .
Sample Input 2
1
998244352
Sample Output 2
998244352
Sample Input 3
9
3 14 159 2653 58979 323846 2643383 27950288 419716939
Sample Output 3
545252774
update @ 2024/3/10 01:49:54