CF1117D.Magic Gems
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Reziba has many magic gems. Each magic gem can be split into M normal gems. The amount of space each magic (and normal) gem takes is 1 unit. A normal gem cannot be split.
Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is N units. If a magic gem is chosen and split, it takes M units of space (since it is split into M gems); if a magic gem is not split, it takes 1 unit.
How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is N units? Print the answer modulo 1000000007 ( 109+7 ). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.
输入格式
The input contains a single line consisting of 2 integers N and M ( 1≤N≤1018 , 2≤M≤100 ).
输出格式
Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is N units. Print the answer modulo 1000000007 ( 109+7 ).
输入输出样例
输入#1
4 2
输出#1
5
输入#2
3 2
输出#2
3
说明/提示
In the first example each magic gem can split into 2 normal gems, and we know that the total amount of gems are 4 .
Let 1 denote a magic gem, and 0 denote a normal gem.
The total configurations you can have is:
- 1111 (None of the gems split);
- 0011 (First magic gem splits into 2 normal gems);
- 1001 (Second magic gem splits into 2 normal gems);
- 1100 (Third magic gem splits into 2 normal gems);
- 0000 (First and second magic gems split into total 4 normal gems).
Hence, answer is 5 .