#P7423. 「PMOI-2」简单构造题

    ID: 7289 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学O2优化生成函数快速傅里叶变换 FFT快速数论变换 NTT

「PMOI-2」简单构造题

Problem Description

In a mock contest, NaCly_Fish encountered the following problem:


Define the weight of a sequence AA of length nn as:

l=1nr=lnfA(l,r)\sum_{l=1}^n\sum_{r=l}^n f_A(l,r)

where fA(l,r)f_A(l,r) is: in the subarray [l,r][l,r] of AA, take the product of the occurrence counts of all elements that have appeared in this subarray, and then multiply it by the product of all elements in the subarray.

You are required to construct a sequence of length nn, where each element is an integer in [1,m][1,m], to maximize its weight.


She could not do it, so she uniformly randomly picked nn integers from [1,m][1,m] to form a sequence, and then output its weight.

Of course, her program got zero points. However, she wants to know the expected weight of the generated sequence.

To avoid precision issues, you need to output the answer modulo 998244353998244353.

Input Format

One line with two positive integers n,mn, m.

Output Format

Output one line with one integer, representing the answer.

3 2
623902740
5 3
887328630
80 233
913763047
114514 19260817
850727003

Hint

[Explanation of Sample 1]

Clearly there are 88 possible sequences: $[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]$.

Their weights are 10,12,12,23,12,17,23,4610,12,12,23,12,17,23,46, respectively, so the expectation is 1558\frac{155}{8}.

[Explanation of Sample 2]

The expectation is 76842243\frac{76842}{243}.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (5 pts): 1n,m81\le n,m \le 8.
  • Subtask 2 (7 pts): 1n,m1001\le n,m \le 100.
  • Subtask 3 (11 pts): 1n,m4001 \le n,m \le 400.
  • Subtask 4 (13 pts): 1n,m50001\le n,m \le 5000.
  • Subtask 5 (25 pts): 1n50001\le n \le 5000.
  • Subtask 6 (39 pts): no additional constraints.

For 100%100\% of the testdata, 1n2×1051\le n \le 2 \times 10^5, 1m1081\le m \le 10^8.

Translated by ChatGPT 5