#P7454. [THUSC 2017] 如果奇迹有颜色
[THUSC 2017] 如果奇迹有颜色
Description
Now Person B has a cycle consisting of regions. Person B wants to dye these regions using colors.
Person B does not want there to exist consecutive regions among these regions such that all colors appear exactly once. In other words, for any consecutive regions, it must not be the case that all colors appear exactly.
If two colorings can be made exactly the same by rotation, then we consider them essentially the same.
However, if two colorings need to be made exactly the same by reflection (flipping), we do not consider them essentially the same.
For example, if :
We consider and to be essentially the same coloring.
We consider and to be essentially different colorings.
We consider and to be essentially the same coloring.
Person B wants to know the number of essentially different colorings that satisfy the condition. Output the answer modulo .
Input Format
Read input from standard input.
The input consists of one line containing two integers , where denotes the length of the cycle and denotes the number of colors.
Output Format
Write output to standard output.
Output one line with one integer, representing the result of the answer modulo .
6 3
44
120 6
615888898
Hint
For of the test points, . | Test point ID | | | | :----------: | :----------: | :----------: | | 1~2 | | | | 3~8 | is prime | | | 9~14 | is prime | | | 15~19 | No special constraints | | | 20 | | |
Translated by ChatGPT 5
京公网安备 11011102002149号