D. Flowers
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 modulo1000000007 (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).

 

大水,话说这比noip还简单些吧,果然做cf要按x率来做么?\(f[i]=f[i-1]+f[i-k]\)
#include <cstdio>
#include <cstring> const int maxn = 1e5 + ;
const int mod = 1e9 + ; int f[maxn], sum[maxn]; int main() {
int t, k;
scanf("%d%d", &t, &k);
for(int i = ; i < k; ++i) {
f[i] = ;
}
for(int i = k; i <= ; ++i) {
f[i] = f[i - ] + f[i - k];
if(mod <= f[i]) f[i] -= mod;
}
for(int i = ; i <= ; ++i) {
sum[i] = sum[i - ] + f[i];
if(mod <= sum[i]) sum[i] -= mod;
}
while(t--) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", (sum[b] - sum[a - ] + mod) % mod);
} return ;
}

最新文章

  1. vs2010静态链接MFC库报链接错误
  2. ubuntu16.04 + ubuntu + apache2 配置apache解析php
  3. java的debug和release编译方式
  4. ls按时间排序输出文件列表
  5. Increasing Triplet Subsequence
  6. URAL 1654 Cipher Message 解题报告
  7. opengl中拾取操作的实现
  8. codeforces 431 D. Random Task 组合数学
  9. Python实现nb(朴素贝叶斯)
  10. 黑马程序员_&lt;&lt;StringBuffer,包装类&gt;&gt;
  11. ConcurrentHashmap中的size()方法简单解释
  12. java创建线程的三种方法
  13. bzoj4044 [Cerc2014] Virus synthesis
  14. fprintf中使用stderr
  15. python 修改dataframe的列名
  16. gcc和gdb使用笔记
  17. delphi treeview checkbox
  18. 贪心算法-Best cow line-字典序问题
  19. 使用web页面实现oracle的安装和测试
  20. Java8 新特性Stream 的学习和使用方法

热门文章

  1. python基础之赋值/深copy/浅copy
  2. python数据结构(1)
  3. RACCommand
  4. IOS方形头像如何变成圆形
  5. Maven项目导出jar包配置
  6. Android 6.0 7.0 8.0 一个简单的app内更新版本-okgo app版本更新
  7. call 大佬 三分姿势
  8. [转载]mysql下载安装
  9. bzoj 2111 [ZJOI2010]Perm 排列计数(DP+lucas定理)
  10. 矩阵 matrix