#abc298e. E - Unfair Sugoroku
E - Unfair Sugoroku
Score : points
问题陈述
高桥和青木将进行一场 sugoroku 游戏。
高桥从点 开始,青木从点 开始。他们轮流投掷骰子。
高桥的骰子显示数字 的概率相等,而青木的骰子显示数字 的概率也相等。
当位于点 的玩家投掷骰子且显示数字 时,他将移动到点 。
第一个到达点 的玩家赢得游戏。
求在高桥先行的情况下,他赢得游戏的概率对 取模的结果。
如何计算模 下的概率 可以证明所求概率总是有理数。此外,本问题的约束条件保证了,如果该概率表示为不可约分数 ,则 不会被 整除。
这里存在一个唯一的整数 ,满足 且 。请报告这个 值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi and Aoki will play a game of sugoroku.
Takahashi starts at point , and Aoki starts at point . They will take turns throwing dice.
Takahashi's die shows with equal probability, and Aoki's shows with equal probability.
When a player at point throws his die and it shows , he goes to point .
The first player to reach point wins the game.
Find the probability that Takahashi wins if he goes first, modulo .
How to find a probability modulo It can be proved that the sought probability is always rational. Additionally, the constraints of this problem guarantee that, if that probability is represented as an irreducible fraction , then is indivisible by .
Here, there is a unique integer between and such that . Report 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
4 2 3 3 2
Sample Output 1
665496236
If Takahashi's die shows or in his first turn, he goes to point and wins.
If Takahashi's die shows in his first turn, he goes to point , and Aoki will always go to point in the next turn and win.
Thus, Takahashi wins with the probability .
Sample Input 2
6 4 2 1 1
Sample Output 2
1
The dice always show .
Here, Takahashi goes to point , Aoki goes to point , and Takahashi goes to point , so Takahashi always wins.
Sample Input 3
100 1 1 10 10
Sample Output 3
264077814
update @ 2024/3/10 12:22:34