QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#13238. Bracelet Strengthening

统计

Little H is a magician who owns a bracelet. This bracelet consists of $n$ beads, which are arranged in a circle. Initially, the reinforcement state of every bead is "unreinforced".

Little H now wants to reinforce this bracelet. Specifically, the reinforcement process is as follows:

  1. Little H lays the bracelet flat on a table.
  2. Little H selects a bead $c$ on the bracelet and decides to reinforce it.
  3. Little H can choose any one of $k$ reinforcement methods to reinforce bead $c$. Let's assume Little H chooses the $i$-th reinforcement method ($1 \le i \le k$).
  4. Regardless of the previous reinforcement state of bead $c$, after the reinforcement, its state becomes "$i$-reinforced".
  5. At the same time, the reinforcement states of the two beads adjacent to $c$ become "unreinforced".

Little H can continue to reinforce this bracelet. The reinforcement can go on indefinitely, but Little H has discovered that the number of different bracelets that can be obtained this way is finite. Now, Little H wants to know how many different bracelets can be produced by using any number of reinforcements. Two bracelets are considered the same if and only if, after appropriately rotating one of them, the reinforcement states of the $n$ beads forming it are identical to the other. Please output the answer modulo $10^9 + 7$.

Input

A single line containing two integers $n$ and $k$.

Output

A single integer representing the number of possible configurations modulo $10^9 + 7$.

Examples

Input 1

4 10

Output 1

66

Input 2

1234 5678

Output 2

902765791

Subtasks

For all data, $n \ge 2$.

Test Case ID $n$ $k$ Test Case ID $n$ $k$
1 $= 4$ $= 1000$ 11 $\le 10^3$ $\le 10^9$
2 $\le 10$ $\le 4$ 12 $\le 2 \times 10^6$
3 $\le 12$ $\le 5$ 13
4 $\le 14$ $\le 5$ 14
5 $\le 18$ $\le 5$ 15
6 $\le 22$ $\le 6$ 16 $\le 10^9$
7 $\le 30$ $\le 7$ 17
8 $\le 10^3$ $\le 10^9$ 18
9 19
10 20

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.