BZOJ4403
Flapper Act + \ (Lucas \) Theorem
Consider the total number of programs, corresponding to the \ (R-L + 1 \ ) put position \ (n-\) block things, can hold the position, as seen by the total number of programs interposer method \ (C_ {n + r-l + 1} ^ {n} -1 \)
Since \ (n, n + r- l + 1 \) range is too large, a smaller modulus, consider \ (Lucas \) Theorem
\ (Lucas \) Theorem: When \ (P \) when a prime number, \ (C_ {n-} ^ {m} \ equiv C_ {n-\ BMOD P} ^ {m \ BMOD P} * C_ {n-/ P} ^ {m / p} (\ bmod p) \)
This allows the number of combinations of the upper and lower modulus of less than, the complexity of the \ (O (T * mod) \)
Code:
#include<bits/stdc++.h>
using namespace std;
int T,n,l,r;
long long jie[1000010],fan[1000010];
const int mod=1e6+3;
long long pw(long long x,int k){
long long ans=1;
while(k){
ans=(ans*x)%mod;
x=(x*x)%mod;
k/=2;
}
return ans;
}
long long rev(long long x){return pw(x,mod-2);}
long long C(int x,int y){
return jie[x]*fan[x-y]%mod*fan[y]%mod;
}
long long Lucas(int x,int y){
if(x<y) return 0;
if(x<mod&&y<mod) return C(x,y);
return Lucas(x/mod,y/mod)*Lucas(x%mod,y%mod)%mod;
}
int main(){
scanf("%d",&T);
jie[0]=1;
for(int i=1;i<=1000002;i++) jie[i]=(jie[i-1]*i)%mod;
fan[1000002]=rev(jie[1000002]);
for(int i=1000002;i>=1;i--) fan[i-1]=(fan[i]*i)%mod;
while(T--){
scanf("%d %d %d",&n,&l,&r);
printf("%lld\n",(Lucas(n+r-l+1,n)+mod-1)%mod);
}
}