No.1897 Sum of 2nd Max
タグ : / 解いたユーザー数 87
作問者 :
miscalc
Problem Statement
There are $K^N$ sequences of length $N$ consisting of integers between $1$ and $K$, inclusive. Over all of these sequences, find the sum of "the element that comes $2$-nd from the front when the sequence is sorted in descending order", modulo $998244353$.
Constraints
- All input values are integers.
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq K \leq 2 \times 10^5$
Input
The input is given from standard input in the following format.$N$ $K$
Output
Output the answer. Print a newline at the end.
Sample
Sample 1
Input
2 3
Output
14
There are $9$ sequences of length $2$ whose elements are all integers between $1$ and $3$, inclusive. For each of them, the element that comes $2$-nd when sorted in descending order is as follows.
- $(1, 1) \rightarrow 1$
- $(1, 2) \rightarrow 1$
- $(1, 3) \rightarrow 1$
- $(2, 1) \rightarrow 1$
- $(2, 2) \rightarrow 2$
- $(2, 3) \rightarrow 2$
- $(3, 1) \rightarrow 1$
- $(3, 2) \rightarrow 2$
- $(3, 3) \rightarrow 3$
Therefore, the desired sum is $1 + 1 + 1 + 1 + 2 + 2 + 1 + 2 + 3 = 14$.
Sample
Sample 2
Input
3 2
Output
12
There are $8$ sequences of length $3$ whose elements are all between $1$ and $2$, inclusive. For each of them, the element that comes $2$-nd when sorted in descending order is as follows.
- $(1, 1, 1) \rightarrow 1$
- $(1, 1, 2) \rightarrow 1$
- $(1, 2, 1) \rightarrow 1$
- $(1, 2, 2) \rightarrow 2$
- $(2, 1, 1) \rightarrow 1$
- $(2, 1, 2) \rightarrow 2$
- $(2, 2, 1) \rightarrow 2$
- $(2, 2, 2) \rightarrow 2$
Therefore, the desired sum is $1 + 1 + 1 + 2 + 1 + 2 + 2 + 2 = 12$.
Sample 3
Input
9 5
Output
8768415
Sample 4
Input
200000 200000
Output
77687822
Find the sum modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。