CF1117D.Magic Gems

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Reziba has many magic gems. Each magic gem can be split into MM normal gems. The amount of space each magic (and normal) gem takes is 11 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 NN units. If a magic gem is chosen and split, it takes MM units of space (since it is split into MM gems); if a magic gem is not split, it takes 11 unit.

How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is NN units? Print the answer modulo 10000000071000000007 (109+710^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 拥有许多魔法宝石。每颗魔法宝石可以分裂成 MM 颗普通宝石。每颗魔法宝石(以及每颗普通宝石)所占空间均为 11 单位。普通宝石无法再分裂。

Reziba 希望选出若干颗魔法宝石,并对其中一部分进行分裂,使得最终得到的所有宝石所占总空间恰好为 NN 单位。若某颗魔法宝石被选中并分裂,则它占据 MM 单位空间(因为它分裂成了 MM 颗宝石);若某颗魔法宝石被选中但未分裂,则它仅占据 11 单位空间。

Reziba 有多少种不同的最终宝石集合配置,使得所占总空间恰好为 NN 单位?请将答案对 10000000071000000007(即 109+710^9+7)取模后输出。若两种配置中 Reziba 所选魔法宝石的总数不同,或 Reziba 进行分裂的宝石下标集合不同,则认为这两种配置不同。

输入格式

The input contains a single line consisting of 22 integers NN and MM (1≤N≤10181 \le N \le 10^{18}, 2≤M≤1002 \le M \le 100).

输入包含一行,其中为两个整数 NN 和 MM(1≤N≤10181 \le N \le 10^{18},2≤M≤1002 \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 NN units. Print the answer modulo 10000000071000000007 (109+710^9+7).

输出一个整数,表示在总占用空间恰好为 NN 个单位的前提下,最终宝石集合的配置总数。答案对 10000000071000000007(即 109+710^9+7)取模。

输入输出样例

  • 输入#1

    4 2

    输出#1

    5
  • 输入#2

    3 2

    输出#2

    3

说明/提示

In the first example each magic gem can split into 22 normal gems, and we know that the total amount of gems are 44.

Let 11 denote a magic gem, and 00 denote a normal gem.

The total configurations you can have is:

  • 11111 1 1 1 (None of the gems split);
  • 00110 0 1 1 (First magic gem splits into 22 normal gems);
  • 10011 0 0 1 (Second magic gem splits into 22 normal gems);
  • 11001 1 0 0 (Third magic gem splits into 22 normal gems);
  • 00000 0 0 0 (First and second magic gems split into total 44 normal gems).

Hence, answer is 55.

在第一个例子中,每颗魔法宝石可以分裂成 22 颗普通宝石,且已知宝石总数为 44。

用 11 表示一颗魔法宝石,用 00 表示一颗普通宝石。

所有可能的排列方式为:

  • 11111 1 1 1(没有任何宝石分裂);
  • 00110 0 1 1(第一颗魔法宝石分裂成 22 颗普通宝石);
  • 10011 0 0 1(第二颗魔法宝石分裂成 22 颗普通宝石);
  • 11001 1 0 0(第三颗魔法宝石分裂成 22 颗普通宝石);
  • 00000 0 0 0(第一颗和第二颗魔法宝石共分裂成 44 颗普通宝石)。

因此,答案为 55。

输入解题思路,AI测评打分。不知道怎么写?

首页