#abc299h. Ex - Dice Sum Infinity
Ex - Dice Sum Infinity
Score : points
问题描述
Takahashi 拥有一枚无偏向的六面骰子和一个小于 的正整数 。每次投掷骰子时,它会独立且等概率地显示出数字 ,与其他试验的结果无关。
Takahashi 将执行以下步骤。最初,。
- 投掷骰子并将 增加 。
- 让 为目前为止所显示数字的总和。如果 是 的倍数,则结束该过程。
- 返回步骤 1。
求在该过程结束时 的期望值,结果对 取模。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has an unbiased six-sided die and a positive integer less than . Each time the die is cast, it shows one of the numbers with equal probability, independently of the outcomes of the other trials.
Takahashi will perform the following procedure. Initially, .
- Cast the die and increment by .
- Let be the sum of the numbers shown so far. If is a multiple of , quit the procedure.
- Go back to step 1.
Find the expected value of at the end of the procedure, modulo .
Notes
Under the constraints of this problem, it can be shown that the expected value of is represented as an irreducible fraction , and there is a unique integer such that . Print this .
Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print a single line containing the answer.
Sample Input 1
1
Sample Output 1
291034221
The expected value of at the end of the procedure is approximately , and when represented modulo .
Sample Input 2
720357616
Sample Output 2
153778832
update @ 2024/3/10 12:25:22