This page is still under construction.

Parts of this page are still being built. What you see may change.

Coloring Practice (Large)

Time limit3sMemory limit512 MB

Summary
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 nn-gon with kk colors. Some colors may go unused, and one color may be used on several vertices.

Number the vertices 00 to n−1n-1 clockwise. A rotation sends vertex ii to vertex i+ji+j, and a reflection sends vertex ii to vertex j−ij-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.

1≤n≤1091 \le n \le 10^9, 1≤k≤251 \le k \le 25

Output

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

Examples2

  1. Example 1

    Input
    6 2
    
    Expected output
    8
    
  2. Example 2

    Input
    3 3
    
    Expected output
    3