#P1316. Mivik 写书
Mivik 写书
Description
Mivik’s keyboard has different keys, corresponding to different characters. Since Mivik cannot write articles, he randomly presses keys with equal probability, producing an article.
Mivik defines the complexity of an article as the number of all non-empty essentially different substrings in the article. We consider two strings essentially different if and only if their lengths are different, or they differ at any character position. For example, the complexity of the article abaa is 8, because it has 8 non-empty essentially different substrings: a, b, ab, ba, aa, aba, baa, abaa.
Now Mivik wants to know the expected complexity of this article. Since Mivik does not like strange-looking decimals, you only need to output the expected complexity modulo .
Input Format
One line with two integers and , as described above.
Output Format
One line with one integer, representing the answer modulo .
2 2
500000006
3 3
5
3 4
250000007
Hint
Sample Explanation
Sample 1: Suppose the characters on the keyboard are a and b. Then there are four possible articles: aa, ab, ba, bb. Their complexities are 2, 3, 3, 2 respectively, so the answer is , which modulo equals 500000006.
Constraints
For all data, , .
Subtask 1 (10 pts): .
Subtask 2 (20 pts): .
Subtask 3 (20 pts): .
Subtask 4 (50 pts): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号