题干:
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).
Input
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 ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007(109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
题目大意:
把红花和白花摆成一排,并且要求若出现白花,它们连续的数量必须是k的倍数。
给我们 n,接下来的n次询问。和k (n,k<100000)
每行 一个 a和b。
设f(k)为长度为k的满足条件的一排花 的 可能的数量
最后求f(a)+f(a+1)+...+f(b)
(不要理解成给定一个区间一共b个,去求a到b的,而是一共a个,一共a+1个....一共b个 的可能情况的和)
另一个题目大意:
话说某个幸运的小伙伴X拿到了kevin女神送的蛋糕,然而他的吃法非常奇特,他独创了两种吃蛋糕的办法:一、一次吃一整个蛋糕;二、一次吃k个蛋糕。
那么,当蛋糕数量为x1到x2之间时,一共能有几种不同的吃法呢?
由于答案很大,输出结果mod 1000000007的值
解题报告:
直接dp就完事了,然后再维护一个前缀和。如果按照第一种题意,那就看AC代码2,第二种题意就看AC代码1。但是第一种题意可以转化成第二种,因为不管什么花其实可以看成是同一种,只不过有两种摆法就是了。
AC代码1:
#include
#include
#include
#include
#include
AC代码2:
#include
#include
#include
#include
#include