問題一覧 > 通常問題

No.1897 Sum of 2nd Max

レベル : / AI推定難易度 : 1250 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 87
作問者 : Shirotsume / テスター : miscalc ygussany polylogK
お気に入りにしたユーザー ProblemId : 7324 / 自分の提出
問題文最終更新日: 2022-04-03 01:55:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 338 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。