P29194 [洛谷] 「PMOI-2」Simple Construction Problem
提高+
题目描述

Problem Description

During a mock competition, NaCly_Fish encountered a problem like this:

Define the weight of a sequence \( A \) of length \( n \) as:

\[ \sum_{l=1}^n \sum_{r=l}^n f_A(l,r) \]

where \( f_A(l,r) \) is the product of the occurrences of all elements that appear within the interval \([l,r]\) in \( A \), multiplied by the product of all elements in the interval.

The task is to construct a sequence of length \( n \) where each element is an integer from \([1,m]\), maximizing its weight.

She didn't know how to solve it, so she randomly selected \( n \) integers from \([1,m]\) to form a sequence and then output its weight.

Of course, she didn't score any points with this program; but she wants to know the expected weight of the generated sequence.

To prevent precision issues, the answer needs to be modulo \( 998244353 \).

Input Format

A line containing two positive integers \( n \) and \( m \).

Output Format

Output a single integer, representing the answer.

Sample Input and Output

Input Sample #1

3 2

Output Sample #1

623902740

Input Sample #2

5 3

Output Sample #2

887328630

Input Sample #3

80 233

Output Sample #3

913763047

Input Sample #4

114514 19260817

Output Sample #4

850727003

Notes

Sample 1 Explanation

There are 8 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]\].

The weights are \(10, 12, 12, 23, 12, 17, 23, 46\) respectively, and the expected value is \(\frac{155}{8}\).

Sample 2 Explanation

The expected value is \(\frac{76842}{243}\).

Data Range

This problem uses subtask testing.

  • Subtask 1 (5 pts): \(1 \le n, m \le 8\);
  • Subtask 2 (7 pts): \(1 \le n, m \le 100\);
  • Subtask 3 (11 pts): \(1 \le n, m \le 400\);
  • Subtask 4 (13 pts): \(1 \le n, m \le 5000\);
  • Subtask 5 (25 pts): \(1 \le n \le 5000\);
  • Subtask 6 (39 pts): No special restrictions.

For \(100\%\) of the data, \(1 \le n \le 2 \times 10^5\), \(1 \le m \le 10^8\).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2
样例输出
623902740