#arc176f. F - Colorful Star

F - Colorful Star

Score: 10001000 points

问题陈述

有一棵包含 NM+1NM+1 个顶点的树,编号从 00NMNM。第 ii 条边(1iNM1 \le i \le NM)连接顶点 iimax(iN,0)\max(i-N,0)

最初,顶点 ii 被涂成颜色 imodNi \bmod N。你可以执行以下操作零次或多次:

  • 选择两个由边连接的顶点 uuvv。将顶点 uu 的颜色重新涂成顶点 vv 的颜色。

在操作后,找出可能的树的数量,对 998244353998244353 取模。如果某个顶点的颜色不同,则区分两棵树。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a tree with NM+1NM+1 vertices numbered 00 to NMNM. The ii-th edge (1iNM1 \le i \le NM) connects vertices ii and max(iN,0)\max(i-N,0).

Initially, vertex ii is colored with color imodNi \bmod N. You can perform the following operation zero or more times:

  • Choose two vertices uu and vv connected by an edge. Repaint the color of vertex uu with that of vertex vv.

Find the number, modulo 998244353998244353, of possible trees after the operations. Two trees are distinguished if and only if some vertex has different colors.

Constraints

  • 1N,M2×1051 \le N, M \le 2 \times 10^5

Input

The input is given from Standard Input in the following format:

NN MM

Output

Print the answer.

Sample Input 1

3 1

Sample Output 1

42

One possible sequence of operations is as follows. Including this one, there are 4242 possible final trees.

Sample Input 2

4 2

Sample Output 2

219100

Sample Input 3

20 24

Sample Output 3

984288778

Sample Input 4

123456 112233

Sample Output 4

764098676