#P6858. Amazing John and the Fat Head Fish Challenge

    ID: 20065 Type: Default 1000ms 256MiB

Amazing John and the Fat Head Fish Challenge

Amazing John and the Fat Head Fish Challenge

After a long series of battles, Amazing John discovered a method to defeat the fat head fish. There are two types of fat head fish:

  • Shielded fish: There are n fish carrying a Saint Shield. When a shielded fish is hit by a toxic attack it is immune to that attack, but its shield is destroyed. Immediately after a fish loses its shield, all other currently alive fish that do not have a shield are granted a Saint Shield.
  • Unshielded fish: There are m fish without any shield.

Each toxic attack is applied to one of the still‐alive fish chosen uniformly at random. The toxic damage instantly kills any fish that does not have a Saint Shield. The process continues until all fish are dead. Find the expected number of toxic attacks required to kill all the fat head fish. Print the answer modulo
\(998244353\).

Note on mechanics:

  • Saint Shield: When a shielded fish is hit, it negates the damage and loses its shield.
  • Fat Head Fish: When a fish loses its shield from an attack, each other fish that is both alive and unshielded immediately receives a Saint Shield.
  • Toxic Damage: A toxic attack instantly kills a fish if it does not have a shield.

All formulas are given in \(\LaTeX\) format. For example, the canonical state when there are \(T\) fish with exactly one unshielded (vulnerable) fish has an expected additional attack count given by:

\[ H(T)=\frac{T^2+3T-2}{2}. \]

In the initial state the fish counts are as follows:

\[ \text{Shielded fish} = n, \quad \text{Unshielded fish} = m. \]

If \(m=0\) (i.e. all fish are shielded), a single attack on any fish results in it losing its shield and triggering the buff, leading to a state transition. In this case the expected number of attacks is computed as:

\[ A(n)=\frac{n(n+3)}{2}. \]</p>

For \(m>0\), let \(A(n, m)\) denote the expected number of attacks from an initial state with \(n\) shielded and \(m\) unshielded fish. Then for \(m\ge2\) the recurrence is:

\[ A(n,m)=1+\frac{n}{n+m}H(n+m)+\frac{m}{n+m}A(n, m-1), \]

with the base case

\[ A(n,1)=\frac{n^2+5n+2}{2}. \]

Your task is to compute \(A(n,m)\) modulo \(998244353\).

inputFormat

The input consists of a single line containing two integers n and m separated by a space. Here, n is the number of shielded fish and m is the number of unshielded fish.

Constraints: 0 ≤ n, m ≤ 105 (for example).

outputFormat

Output a single integer — the expected number of toxic attacks required to kill all the fat head fish, taken modulo \(998244353\).

sample

1 1
4