# 【BZOJ】【lucas定理】4403: 序列统计

$m=R-L+1$$m=R-L+1$如果长度确定为$n$$n$，相当于求$\sum _{i=1}^{m}{x}_{i}=n$$\sum_{i=1}^{m}x_i=n$，用插板法得答案为$\left(\genfrac{}{}{0}{}{n+m-1}{m-1}\right)$$n+m-1\choose m-1$，然后就是一波骚操作：

$\left(\genfrac{}{}{0}{}{x}{y}\right)=\left(\genfrac{}{}{0}{}{x-1}{y}\right)+\left(\genfrac{}{}{0}{}{x-1}{y-1}\right)$${x\choose y}={x-1\choose y}+{x-1\choose y-1}$

$\sum _{i=1}^{n}\left(\genfrac{}{}{0}{}{i+m-1}{m-1}\right)=\left(\genfrac{}{}{0}{}{n+m-1}{n}\right)+\left(\genfrac{}{}{0}{}{n-1+m-1}{n-1}\right)+...+\left(\genfrac{}{}{0}{}{m+1}{2}\right)+\left(\genfrac{}{}{0}{}{m}{1}\right)+\left(\genfrac{}{}{0}{}{m}{0}\right)-1\phantom{\rule{0ex}{0ex}}=\sum _{i=1}^{n}\left(\genfrac{}{}{0}{}{i+m-1}{m-1}\right)=\left(\genfrac{}{}{0}{}{n+m-1}{n}\right)+\left(\genfrac{}{}{0}{}{n-1+m-1}{n-1}\right)+...+\left(\genfrac{}{}{0}{}{m+1}{2}\right)+\left(\genfrac{}{}{0}{}{m+1}{1}\right)-1\phantom{\rule{0ex}{0ex}}=\left(\genfrac{}{}{0}{}{n+m}{n}\right)-1$

## 代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int tt=1000003;
int T,f[tt+6],inv[tt+6];
int C(int x,int y){if(x<y)return 0;return (LL)f[x]*inv[y]%tt*inv[x-y]%tt;}
int lucas(int x,int y){if(!y)return 1;return (LL)C(x%tt,y%tt)*lucas(x/tt,y/tt)%tt;}
int main(){
freopen("sequence.in","r",stdin);freopen("sequence.out","w",stdout);
f[0]=inv[0]=inv[1]=1;
for(int i=1;i<=tt;i++)f[i]=(LL)f[i-1]*i%tt;
for(int i=2;i<=tt;i++)inv[i]=(tt-(LL)tt/i*inv[tt%i]%tt)%tt;
for(int i=2;i<=tt;i++)inv[i]=(LL)inv[i-1]*inv[i]%tt;
scanf("%d",&T);
for(int n,l,r;T;T--)scanf("%d%d%d",&n,&l,&r),printf("%d\n",(lucas(r-l+1+n,n)-1+tt)%tt);
return 0;
}