Coloring Practice (Large)

Count colorings of a regular n-gon up to rotation, reflection, and arbitrary permutation of the k colors, modulo 1e9+7.

Hard9CombinatoricsMathNumber theoryBit manipulationNo attempts yetTime limit3sMemory limit512 MB

Problem

You color the vertices of a regular nn-gon with kk colors. Some colors may go unused, and one color may be used on several vertices.

Number the vertices 00 to n1n-1 clockwise. A rotation sends vertex ii to vertex i+ji+j, and a reflection sends vertex ii to vertex jij-i, where every vertex number is taken modulo nn.

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 XX and YY, recolor every XX vertex to YY, and recolor every YY vertex to XX. This operation is allowed even when no vertex has color XX, or no vertex has color YY.

Count the different colorings.

Input

The first line contains nn and kk, separated by one space.

1n1091 \le n \le 10^9, 1k251 \le k \le 25

Output

Print the number of different colorings modulo 1,000,000,007 on one line.