#abc298e. E - Unfair Sugoroku

E - Unfair Sugoroku

Score : 500500 points

问题陈述

高桥和青木将进行一场 sugoroku 游戏。
高桥从点 AA 开始,青木从点 BB 开始。他们轮流投掷骰子。
高桥的骰子显示数字 1,2,,P1, 2, \ldots, P 的概率相等,而青木的骰子显示数字 1,2,,Q1, 2, \ldots, Q 的概率也相等。
当位于点 xx 的玩家投掷骰子且显示数字 ii 时,他将移动到点 min(x+i,N)\min(x + i, N)
第一个到达点 NN 的玩家赢得游戏。
求在高桥先行的情况下,他赢得游戏的概率对 998244353998244353 取模的结果。

如何计算模 998244353998244353 下的概率 可以证明所求概率总是有理数。此外,本问题的约束条件保证了,如果该概率表示为不可约分数 yx\frac{y}{x},则 xx 不会被 998244353998244353 整除。
这里存在一个唯一的整数 zz,满足 0z9982443520 \leq z \leq 998244352xzy(mod998244353)xz \equiv y \pmod {998244353}。请报告这个 zz 值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi and Aoki will play a game of sugoroku.
Takahashi starts at point AA, and Aoki starts at point BB. They will take turns throwing dice.
Takahashi's die shows 1,2,,P1, 2, \ldots, P with equal probability, and Aoki's shows 1,2,,Q1, 2, \ldots, Q with equal probability.
When a player at point xx throws his die and it shows ii, he goes to point min(x+i,N)\min(x + i, N).
The first player to reach point NN wins the game.
Find the probability that Takahashi wins if he goes first, modulo 998244353998244353.

How to find a probability modulo 998244353998244353 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 yx\frac{y}{x}, then xx is indivisible by 998244353998244353.
Here, there is a unique integer zz between 00 and 998244352998244352 such that xzy(mod998244353)xz \equiv y \pmod {998244353}. Report this zz.

Constraints

  • 2N1002 \leq N \leq 100
  • 1A,B<N1 \leq A, B < N
  • 1P,Q101 \leq P, Q \leq 10
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN AA BB PP QQ

Output

Print the answer.

Sample Input 1

4 2 3 3 2

Sample Output 1

665496236

If Takahashi's die shows 22 or 33 in his first turn, he goes to point 44 and wins.
If Takahashi's die shows 11 in his first turn, he goes to point 33, and Aoki will always go to point 44 in the next turn and win.
Thus, Takahashi wins with the probability 23\frac{2}{3}.

Sample Input 2

6 4 2 1 1

Sample Output 2

1

The dice always show 11.
Here, Takahashi goes to point 55, Aoki goes to point 33, and Takahashi goes to point 66, so Takahashi always wins.

Sample Input 3

100 1 1 10 10

Sample Output 3

264077814

update @ 2024/3/10 12:22:34