QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#15201. 好的字符串

Statistiques

我们称一个字符串为“好字符串”,当且仅当该字符串不包含长度大于 $2$ 的回文子串。

现在我们想知道,在所有长度恰好为 $n$ 且字符集大小为 $m$ 的字符串中,有多少个不同的好字符串(不一定需要使用字符集中的所有字符)。

输入格式

仅一行,包含两个整数 $n, m$ ($1 \le n \le 10^6, 1 \le m \le 10^9$)。

输出格式

输出一个整数,表示不同的好字符串的数量,答案对 $1000000007$ 取模。

样例

输入样例 1

3 3

输出样例 1

18

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.