Coloring Practice (Large)
Time limit3sMemory limit512 MB
Count colorings of a regular n-gon up to rotation, reflection, and arbitrary permutation of the k colors, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Combinatorics, Math, Number theory, Bit manipulation
- Solved
- No attempts yet
Problem
You color the vertices of a regular -gon with colors. Some colors may go unused, and one color may be used on several vertices.
Number the vertices to clockwise. A rotation sends vertex to vertex , and a reflection sends vertex to vertex , where every vertex number is taken modulo .
Two colorings count as one and the same case when a finite sequence of the following three operations turns one into the other.
- Rotate the polygon.
- Flip the polygon.
- Pick two different colors and , recolor every vertex to , and recolor every vertex to . This operation is allowed even when no vertex has color , or no vertex has color .
Count the different colorings.
Input
The first line contains and , separated by one space.
,
Output
Print the number of different colorings modulo 1,000,000,007 on one line.