#P7454. [THUSC 2017] 如果奇迹有颜色

    ID: 6437 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划,dp数学2017状态压缩,状压线性递推,递推式

[THUSC 2017] 如果奇迹有颜色

Description

Now Person B has a cycle consisting of nn regions. Person B wants to dye these nn regions using mm colors.

Person B does not want there to exist mm consecutive regions among these nn regions such that all mm colors appear exactly once. In other words, for any mm consecutive regions, it must not be the case that all mm 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 n=4,m=4n=4,m=4:

We consider 1,2,3,41,2,3,4 and 3,4,1,23,4,1,2 to be essentially the same coloring.

We consider 1,2,3,41,2,3,4 and 4,3,2,14,3,2,1 to be essentially different colorings.

We consider 1,2,1,21,2,1,2 and 2,1,2,12,1,2,1 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 109+710^9+7.

Input Format

Read input from standard input.

The input consists of one line containing two integers n,mn,m, where nn denotes the length of the cycle and mm 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 109+710^9+7.

6 3
44
120 6
615888898

Hint

For 100%100\% of the test points, 1n109,2m71\le n\le 10^9,2\le m\le7. | Test point ID Id\operatorname*{Id} | nn | mm | | :----------: | :----------: | :----------: | | 1~2 | n10n\le10 | m=Id+2m=\operatorname*{Id}+2 | | 3~8 | n105,nn\le 10^5,n is prime | m=Id1m=\operatorname*{Id}-1 | | 9~14 | nn is prime | m=Id7m=\operatorname*{Id}-7 | | 15~19 | No special constraints | m=Id13m=\operatorname*{Id}-13 | | 20 | n=635,643,090n=635,643,090 | m=7m=7 |

Translated by ChatGPT 5