Mr. Ant has 3 boxes and the infinite number of marbles. Now he wants to know the number of ways he can put marbles in these three boxes when the following conditions hold.

1)     Each box must contain at least 1 marble.

2)     The summation of marbles of the 3 boxes must be in between X and Y inclusive.

Now you are given X and Y. You have to find the number of ways Mr. Ant can put marbles in the 3 boxes.

Input

Input starts with an integer T, denoting the number of test cases. Each test case contains two integers X and Y.

Constraints

1<=T<=1000000

1<=X<= Y<=1000000

Output

For each test case, print the required answer modulo 1000000007.

Sample Input

Sample Output

1

4 5

9

Explanation for the first test case

 

1 1 2

Way 01

1 1 3

Way 02

1 2 1

Way 03

1 3 1

Way 04

2 1 1

Way 05

3 1 1

Way 06

1 2 2

Way 07

2 1 2

Way 08

2 2 1

Way 09

Note: use faster i/o method.

n个相同的东西放进三个不同的盒子里,每个盒子至少要有一个

这就是裸的排列组合题

用隔板法很容易知道,对于一个单独的n,答案就是C(n-1,2),令f(x)=C(x-1,2)

对于f(x)的一段求和,显然在n>=3时才有方案,即f(x)定义域x>=3

令g(x)=f(3)+f(4)+...+f(x),那么答案就是g(r)-g(l-1),(考虑到定义域应当是g(r)-g(l)+f(l)不过似乎不这样也行)

然后根据组合数的性质C(2,2)+C(3,2)+...+C(x-1,2)=C(x,3)

所以g(x)=C(x,3)

然后做完了

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000000007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline LL calc(LL a)//return C a 3
{
if (a<)return ;
return a*(a-)*(a-)/%mod;
}
int main()
{
int T=read();
while (T--)
{
LL a=read(),b=read();
printf("%lld\n",(calc(b)-calc(a-)+mod)%mod);
}
}

Spoj ANTP

Spoj-ANTP Mr. Ant & His Problem的更多相关文章

  1. HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  2. HDU5924 Mr. Frog’s Problem

    /* HDU5924 Mr. Frog’s Problem http://acm.hdu.edu.cn/showproblem.php?pid=5924 数论 * */ #include <cs ...

  3. SPOJ Another Longest Increasing Subsequence Problem 三维最长链

    SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...

  4. SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治求三维偏序)

    Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it ...

  5. hdu5924Mr. Frog’s Problem

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  6. SPOJ - LOCKER

    SPOJ - LOCKERhttps://vjudge.net/problem/45908/origin暴力枚举2-102 23 34 2 25 2 36 3 37 2 2 38 2 3 39 3 3 ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. 【无源汇上下界最大流】SGU 194 Reactor Cooling

    题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...

  9. 10.6 CCPC northeast

    1001 Minimum's Revenge 点的编号从 1 到 n ,u  v 的边权是 LCM(u,v) ,求这个图的最下生成树 搞成一颗以 1 为 根 的菊花树 ---------------- ...

随机推荐

  1. python打飞机pro版

    # -*- coding: utf-8 -*- import pygame from sys import exit import random pygame.init() screen = pyga ...

  2. Google Colab免费GPU使用教程(一)

    一.前言 现在你可以开发Deep Learning Applications在Google Colaboratory,它自带免费的Tesla K80 GPU.重点是免费.免费!(国内可能需要tz) 这 ...

  3. uva12264 Risk

    最小值最大,就二分判断. map[i] = '0'+map[i];这样更方便 每个点拆成i,i’,  S连i,cap为a[i],i’连T,cap为1(保证至少剩一个)或mid. i,i’ ,a[i] ...

  4. 第二次团队作业-PANTHER考勤系统需求分析

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  5. JS原型、原型链、构造函数、实例与继承

    https://cloud.tencent.com/developer/article/1408283 https://cloud.tencent.com/developer/article/1195 ...

  6. 实现类似add(1)(2)(3)的函数

    要求实现类似add(1)(2)(3)调用方式的方法,例如add为加法函数,则调用add(1)(2)输出3,调用add(1)(5)(3)输出9. ​ 函数的调用方式是多次调用同一个函数,将每次传入的参数 ...

  7. MAC进入文件夹快捷键

    common + O common+up common+Down shift + common +G

  8. CPP-基础:内存泄露及其检测工具

    [转]浅谈C/C++内存泄露及其检测工具   对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问题.已经有许多技术被研究出来以应对这个问题,比如 Smart Pointer,Garba ...

  9. ewebeditor上传文件大小

    做项目大家都少不了要跟html在线编辑器打交道,这里我把我的一些使用经验及遇到的问题发出来和大家交流一下. Ewebeditor使用说明:一.部署方式:1.直接把压缩目录中的文件拷贝到您的网站发布目录 ...

  10. thinkphp 结合phpexcel实现excel导入

    控制器文件: class ExcelAction extends Action { public function __construct() { import('ORG.Util.ExcelToAr ...