QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#16792. 双回文

统计

回文是指正着读和倒着读都相同的字符串。例如,rotatorlilabba 是回文,但 shalash 不是。

双重回文是指自身是回文,或者由两个(不一定不同)回文拼接而成的字符串。例如,susannapotatoabba 是双重回文,但 zzyzxabaabb 不是。

Dalila 刚刚意识到她的名字是一个双重回文!现在她想知道,有多少个长度最多为 $n$ 且仅由前 $k$ 个英文字母组成的非空字符串也具有这一性质。请帮她求出这个数量,并对 $998\,244\,353$ 取模后输出。

输入格式

唯一的一行包含两个整数 $n$ 和 $k$ —— 字符串的最大长度和字符集大小($1 \le n \le 10^5$;$1 \le k \le 26$)。

输出格式

输出长度最多为 $n$ 且仅由前 $k$ 个英文字母组成的非空双重回文的数量,对 $998\,244\,353$ 取模。

样例

输入样例 1

3 3

输出样例 1

33

输入样例 2

6 2

输出样例 2

114

输入样例 3

42 7

输出样例 3

83419789

说明

在第一个样例中,需要统计的字符串为:a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab, aac, aba, abb, aca, acc, baa, bab, bba, bbb, bbc, bcb, bcc, caa, cac, cbb, cbc, cca, ccb, ccc。

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.