#abc275e. E - Sugoroku 4
E - Sugoroku 4
Score : points
问题描述
Takahashi 正在玩一款名为 sugoroku 的桌面游戏。
棋盘上有 个格子,编号从 到 。Takahashi 从第 号格子出发,目标是到达第 号格子。
游戏中使用了一个轮盘,上面有 个从 到 的数字,每个数字出现的概率相等。Takahashi转动轮盘,并按照轮盘指示的数字移动相应的格子数。如果这将导致他超过第 号格子,则他在第 号格子处掉头,并按超出的格子数返回。
例如,假设 并且 Takahashi 在第 号格子上。如果轮盘显示数字 ,则超过第 格子的格子数为 。因此,他会从第 格子向回走三个格子,最终到达第 格子。
当 Takahashi 到达第 号格子时,他就赢了,游戏结束。
计算当 Takahashi 最多可以转轮盘 次时,他获胜的概率对 取模的结果。
如何打印概率对 取模的结果
可以证明所求概率始终是一个有理数。此外,在本题的约束条件下,当所求概率表示为不可约分数 时,保证 不被 整除。
此时存在一个唯一的整数 ,满足 以及 。请输出这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is playing sugoroku, a board game.
The board has squares, numbered to . Takahashi starts at square and goes for square .
The game uses a roulette wheel with numbers from to that appear with equal probability. Takahashi spins the wheel and moves by the number of squares indicated by the wheel. If this would send him beyond square , he turns around at square and goes back by the excessive number of squares.
For instance, assume that and Takahashi is at square . If the wheel shows , the excessive number of squares beyond square is . Thus, he goes back by three squares from square and arrives at square .
When Takahashi arrives at square , he wins and the game ends.
Find the probability, modulo , that Takahashi wins when he may spin the wheel at most times.
How to print a probability modulo
It can be proved that the sought probability is always a rational number. Additionally, under the Constraints of this problem, when the sought probability is represented as an irreducible fraction , it is guaranteed that is not divisible by .
Here, there is a unique integer between and such that . Print this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 2 1
Sample Output 1
499122177
Takahashi wins in one spin if the wheel shows . Therefore, the probability of winning is .
We have , so the answer to be printed is .
Sample Input 2
10 5 6
Sample Output 2
184124175
Sample Input 3
100 1 99
Sample Output 3
0
update @ 2024/3/10 11:35:26