【题解】BZOJ4403序列统计
hanjicheng · · 个人记录
题面
给定三个正整数
link(因为bzoj崩了,所以只能在loj上提交了)
题解
问题相当于在
转化问题,将从小到大第
于是乎问题变成了在
设
因为
用
记得最后
代码
#include<iostream>
#define ll long long
using namespace std;
ll t;
ll n,l,r,mod,ans;
ll ksm(ll a,ll b,ll p)
{
if(b==0) return 1;
ll k=ksm(a,b>>1,p);
k=(k*k)%p;
if(b&1) return (k*a)%p;
return k;
}
ll C(ll m,ll n,ll p)
{
if(n>m) return 0;
n=min(n,m-n);
ll a=1,b=1;
for(ll i=1;i<=n;i++)
{
b=(b*i)%p;
a=(a*(m-n+i))%p;
}
return (a*ksm(b,p-2,p))%p;
}
ll lucas(ll m,ll n,ll p)
{
if(n==0) return 1;
return (lucas(m/p,n/p,p)*C(m%p,n%p,p))%p;
}
int main()
{
cin>>t;
mod=1000003;
while(t--)
{
cin>>n>>l>>r;
ans=lucas(n+r-l+1,n,mod)-1;
ans=(ans%mod+mod)%mod;
cout<<ans<<endl;
}
return 0;
}