A12441 | Magic Gems
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ ( $10^9+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.
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$ ( $10^9+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 \le N \le 10^{18}$ , $2 \le M \le 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$ ( $10^9+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:
- $1 1 1 1$ (None of the gems split);
- $0 0 1 1$ (First magic gem splits into $2$ normal gems);
- $1 0 0 1$ (Second magic gem splits into $2$ normal gems);
- $1 1 0 0$ (Third magic gem splits into $2$ normal gems);
- $0 0 0 0$ (First and second magic gems split into total $4$ normal gems).
Hence, answer is $5$ .
Let $1$ denote a magic gem, and $0$ denote a normal gem.
The total configurations you can have is:
- $1 1 1 1$ (None of the gems split);
- $0 0 1 1$ (First magic gem splits into $2$ normal gems);
- $1 0 0 1$ (Second magic gem splits into $2$ normal gems);
- $1 1 0 0$ (Third magic gem splits into $2$ normal gems);
- $0 0 0 0$ (First and second magic gems split into total $4$ normal gems).
Hence, answer is $5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted