QOJ.ac

QOJ

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

#15027. If Miracles Had a Color

统计

The BASF company was once the world's largest chemical enterprise. They produced dyes in a rich variety of colors, including Tsinghua Purple, Soul Yellow, Forgive Green, Conference Blue, Advanced Black, Peking University Red, and Album White.

Now, B has a ring consisting of $n$ regions, and B wants to color these $n$ regions using $m$ colors.

B does not want any $m$ consecutive regions in the $n$ regions to contain all $m$ colors. In other words, for any $m$ consecutive regions, it is not allowed for all $m$ colors to appear exactly once.

If two coloring schemes can become identical through rotation, we consider them essentially the same. However, if two schemes require reflection to become identical, we do not consider them essentially the same.

For example, if $n=4, m=4$: We consider $1, 2, 3, 4$ and $3, 4, 1, 2$ to be essentially the same scheme. We consider $1, 2, 3, 4$ and $4, 3, 2, 1$ to be essentially different schemes. We consider $1, 2, 1, 2$ and $2, 1, 2, 1$ to be essentially the same scheme.

B wants to know the number of essentially different schemes that satisfy the condition, modulo $1\,000\,000\,007$.

Input

The input consists of a single line containing two integers $n$ and $m$.

Here, $n$ represents the length of the ring, and $m$ represents the number of colors.

Output

Output a single integer representing the answer modulo $1\,000\,000\,007$.

Examples

Input 1

6 3

Output 1

44

Input 2

120 6

Output 2

615888898

Subtasks

  • For $100\%$ of the test cases, $1 \leq n \leq 1\,000\,000\,000, 2 \leq m \leq 7$.
Data ID $n$ $m$
1 $1 \leq n \leq 10$ $m = 3$
2 $m = 4$
3 $1 \leq n \leq 10^{5}$, $n$ is prime $m = 2$
4 $m = 3$
5 $m = 4$
6 $m = 5$
7 $m = 6$
8 $m = 7$
9 $1 \leq n \leq 10^{9}$, $n$ is prime $m = 2$
10 $m = 3$
11 $m = 4$
12 $m = 5$
13 $m = 6$
14 $m = 7$
15 $1 \leq n \leq 10^{9}$ $m = 2$
16 $m = 3$
17 $m = 4$
18 $m = 5$
19 $m = 6$
20 $n = 635,643,090$ $m = 7$

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.