# Bzoj4403 序列统计

Posted by yjjr's blog on February 6, 2018

Description

Input

1≤N,L,R≤10^9，1≤T≤100，输入数据保证L≤R。

Output

Sample Input

2

1 4 5

2 4 5

Sample Output

2

5

//【样例说明】满足条件的2个序列为[4]和[5]。

Sum{C(i+M-1,M-1)}=C（n+M,M）-1

Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define LL long long
using namespace std;
{
LL f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const LL mod=1e6+3;
LL fac[mod],inv[mod];
void work()
{
fac[0]=fac[1]=inv[0]=inv[1]=1;
rep(i,2,mod-1)fac[i]=fac[i-1]*i%mod;
rep(i,2,mod-1)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
rep(i,1,mod-1)inv[i]=inv[i-1]*inv[i]%mod;
}

LL C(LL n,LL m)
{
if(n<m)return 0;
if(n<mod&&m<mod)return fac[n]*inv[n-m]%mod*inv[m]%mod;
return C(n%mod,m%mod)*C(n/mod,m/mod)%mod;
}

int main()
{
work();
}