QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#9116. DRD 字符串

الإحصائيات

如果一个字符串 $S$ 存在某些非空字符串 $D$ 和 $R$,且 $S$ 是由 $D$、$R$、$D$ 按此顺序连接而成,则称 $S$ 为 DRD 字符串。现在我们可以使用 $M$ 种字母。求长度为 $N$ 的 DRD 字符串的数量,结果对 $998244353$ 取模。

输入格式

输入通过标准输入给出,格式如下:

$N \ M$

  • 所有输入值均为整数。
  • $3 \le N \le 10^6$
  • $1 \le M \le 10^6$

输出格式

在一行中输出答案。

样例

样例输入 1

6 2

样例输出 1

40

样例输入 2

3017 7801

样例输出 2

515391664

说明

如果在样例 1 中我们可以使用 $a$ 和 $b$,那么 abbaabaaaaaa 是长度为 6 的 DRD 字符串,但 abbabbaaabbb 不是。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.