QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#15027. 如果奇迹有颜色

統計

题目描述

法本公司曾经是世界最大的化工企业,他们生产的染料颜色非常丰富,有清华紫,心灵黄,原谅绿,会议蓝,高级黑,北大红,相簿白等。

现在 B 君有一个由 $n$ 个区域组成的环,B君要用 $m$ 种颜色来染这 $n$ 个区域。

B 君不希望在这 $n$ 个区域中存在连续 $m$ 个区域恰好出现所有 $m$ 个颜色。换句话说,对于任意连续 $m$ 个区域,都不能恰好出现所有 $m$ 个颜色。

如果两个方案通过旋转可以变得一模一样,那么我们认为他们是本质相同的;

但是如果两个方案需要通过翻转才能变得一模一样,我们不认为他们是本质相同的。

比如如果 $n=4, m = 4$;

我们认为 $1, 2, 3, 4$ 和 $3, 4, 1, 2$ 是本质相同的方案;

我们认为 $1, 2, 3, 4$ 和 $4, 3, 2, 1$ 是本质不同的方案;

我们认为 $1, 2, 1, 2$ 和 $2, 1, 2, 1$ 是本质相同的方案;

B君希望知道满足条件,本质不同的方案数,输出答案对 $1\,000\,000\,007$ 取模。

输入格式

从标准输入读入数据。

输入一行包含两个整数 $n, m$。

其中 $n$ 表示环的长度,$m$ 表示颜色数。

输出格式

输出到标准输出。

输出一行一个整数,表示答案对 $1\,000\,000\,007$ 取模的结果。

样例

输入

6 3

输出

44

样例

输入

120 6

输出

615888898

子任务

  • 对于 $100\%$ 的测试点, $1 \leq n \leq 1\,000\,000\,000, 2 \leq m \leq 7$。

数据编号$n$$m$
1$1 \leq n \leq 10$$m = 3$
2$m = 4$
3$1 \leq n \leq 10^{5}$, $n$是质数$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$是质数$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$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.