No.2351 Butterfly in Summer
タグ : / 解いたユーザー数 203
作問者 : 👑
Problem Statement
Every butterfly living in the country of yuki has wings divided into $N$ parts, and each part is colored with $1$ color chosen with equal probability from $K$ candidate colors.
Find the probability that, among the parts of this butterfly's wings, $N-1$ parts all have the same color and only the remaining $1$ part has a color different from the other $N-1$ parts, modulo $\bmod 998244353$ as described in the note below.
Notes
It can be proved that the desired value is a rational number. Also, under the constraints of this problem, it can be proved that when the value is expressed as $\frac{Q}{P}$ using $2$ coprime integers $P,Q$, there exists exactly one integer $R$ satisfying $RP \equiv Q \pmod{998244353}$ and $0 \leq R < 998244353$. Output this $R$.
Constraints
- All inputs are integers.
- $3 \leq N \leq 10^5$
- $2 \leq K \leq 10^5$
Input
The input is given from Standard Input in the following format.
$N$ $K$
Output
Output the answer $\bmod 998244353$ as described in the note.
Sample
Sample 1
Input
3 2
Output
249561089
The tuples $(c_1, c_2, c_3)$ of colors painted on the $3$ parts are the following $8$.
- $(c_1, c_2, c_3) = (1,1,1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1), (2,2,2)$
Among these, the $6$ tuples of colors satisfying the condition are $(1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1)$.
Therefore, the desired probability is $\frac{6}{8} = \frac{3}{4}$. Since $4 \times 249561089 \equiv 3 \pmod{998244353}$, output $249561089$.
Sample 2
Input
4 2
Output
499122177
There are $16$ tuples $(c_1, c_2, c_3, c_4)$ of colors painted on the $4$ parts in total. Among these, there are $8$ tuples in total satisfying the condition, such as $(1,1,1,2), (2,1,2,2)$.
Therefore, the desired probability is $\frac{8}{16} = \frac{1}{2}$. Since $2 \times 499122177 \equiv 1 \pmod{998244353}$, output $499122177$.
Sample 3
Input
16 2017
Output
62053606
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。