P18098 [CCPC 2026 Changchun] Kingdom of Mathematics
Background
Another math problem? Is your school a kingdom of mathematics?
Description
Given positive integers $n,k$, there are $n$ people, and each of them holds a positive integer not greater than $k$. Before the operations start, for each positive integer $1\le j \le k$, there are $s_j$ people holding the positive integer $j$.
Then the following operation is repeated until the positive integers held by all people are equal:
- Let $w_i$ be the positive integer held by the $i$-th person. Among all pairs of positive integers $(u,v)$ satisfying $1\le u,v\le n$ and $w_u\neq w_v$, choose one pair uniformly at random and denote it by $(u_0,v_0)$. Then change the positive integer $w_{u_0}$ held by the $u_0$-th person to $w_{v_0}$.
Let $\tau$ be the number of rounds of the operation. Find the variance $\operatorname{Var}(\tau)$ of the random variable $\tau$, modulo $998244353$.
It can be shown that the answer is a rational number, and after it is written in the reduced form $\frac{p}{q}$, the denominator $q$ is not a multiple of $998244353$. In this case there is a unique positive integer $1\le r
Input Format
The first line of the input contains two positive integers $n,k$ ($1\le n \le 10^9$, $1\le k \le \min(n,3\times 10^5)$), representing the number of people and the upper bound of the positive integers held.
The second line contains $k$ positive integers $s_1,s_2,\cdots,s_k$ ($1\le s_i\le n$, $\sum\limits_{i=1}^ks_i=n$), representing the number of people holding each positive integer.
Output Format
Output a single line with one non-negative integer, representing the result of $\operatorname{Var}(\tau) \bmod 998244353$.
Explanation/Hint
For Sample 1, after the first operation there must be exactly two people holding the same positive integer. Let the positive integer they hold be $a$, and let the positive integer held by the other person be $b$.
The next operation must be one of the following two operations, each chosen with equal probability:
- Choose a person holding the positive integer $a$ and change the number in their hand to $b$;
- Choose a person holding the positive integer $b$ and change the number in their hand to $a$.
If the latter is chosen, the process ends; otherwise, the state after the operation is equivalent to the state before the operation.
Therefore, the distribution of $\tau$ is $P(\tau=x)=\frac{1}{2^{x-1}},x=2,3,\dots$, from which the expectation of $\tau$ is $\sum\limits_{x\ge 2}\frac{x}{2^{x-1}}=3$. Substituting it into the formula gives $\operatorname{Var}(\tau)=\sum\limits_{x\ge 2}\frac{(x-3)^2}{2^{x-1}}=2$.
Translated by QwenWork