CF474D.Flowers

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.

Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).

我们曾见过土拨鼠为鼹鼠的午餐设计的小游戏。现在到了土拨鼠的晚餐时间,众所周知,土拨鼠吃花。每顿晚餐,他都会吃一些红花和白花。因此,一顿晚餐可以表示为一个由若干花朵组成的序列,其中一些是白花,另一些是红花。

但要让一顿晚餐变得美味,需满足一条规则:土拨鼠只允许以大小恰好为 kk 的组来吃白花。

现在土拨鼠想知道:他一共能在 aa 到 bb 朵花(含端点)之间有多少种不同的吃法?由于方案数可能非常大,请将结果对 10000000071000000007(即 109+710^9 + 7)取模后输出。

输入格式

Input contains several test cases.

The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases.

The next t lines contain two integers a__i and b__i (1 ≤ a__i ≤ b__i ≤ 105), describing the i-th test.

输入包含多个测试用例。

第一行包含两个整数 tt 和 kk(1 ≤ t, k ≤ 1051 \le t,\,k \le 10^5),其中 tt 表示测试用例的数量。

接下来的 tt 行每行包含两个整数 aia_i 和 bib_i(1 ≤ ai ≤ bi ≤ 1051 \le a_i \le b_i \le 10^5),描述第 ii 个测试用例。

输出格式

Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between a__i and b__i flowers at dinner modulo 1000000007 (109 + 7).

向标准输出打印 t 行。第 i 行应包含土拨鼠在晚餐时吃掉介于 a__i 与 b__i 朵花之间的方案数,结果对 1000000007(即 109+710^9 + 7)取模。

输入输出样例

  • 输入#1

    3 2
    1 3
    2 3
    4 4

    输出#1

    6
    5
    5

说明/提示

  • For K = 2 and length 1 Marmot can eat (R).

  • For K = 2 and length 2 Marmot can eat (RR) and (WW).

  • For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).

  • For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).

  • 当 K=2K = 2 且长度为 1 时,土拨鼠可以吃(R)。

  • 当 K=2K = 2 且长度为 2 时,土拨鼠可以吃(RR)和(WW)。

  • 当 K=2K = 2 且长度为 3 时,土拨鼠可以吃(RRR)、(RWW)和(WWR)。

  • 当 K=2K = 2 且长度为 4 时,土拨鼠可以吃,例如(WWWW)或(RWWR),但例如不能吃(WWWR)。

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

首页