Codeforces Round 271 (Div. 2)
D
Flowers
Codeforces
1700
原题
← CE →
翻译中…

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$ ($10^{9} + 7$).

翻译中…

Input

翻译中…

Input contains several test cases.

翻译中…

The first line contains two integers $*t*$ and $*k*$ ($1 ≤ *t*, *k* ≤ 10^{5}$), 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*} ≤ 10^{5}$), 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 $*a*_{*i*}$ and $*b*_{*i*}$ flowers at dinner modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Note

翻译中…
  • 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*$).
翻译中…

样例

Input #1
3 2
1 3
2 3
4 4
Output #1
6
5
5
InputCopy OutputCopy
题目信息
题号
474D
时间限制
1.5 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。