AcWing 1312. 序列统计
原题链接
中等
作者:
黄亦玫
,
2020-09-17 11:13:58
,
所有人可见
,
阅读 327
#include <iostream>
using namespace std;
const int mod = 1e6 + 3;
typedef long long LL;
int qmi(int a, int b)
{
int res = 1;
while(b)
{
if(b & 1)res = (LL)res * a % mod;
a = (LL)a * a % mod;
b >>= 1;
}
return res;
}
int C(int a, int b)
{
if (a < b) return 0;
int down = 1, up = 1;
for (int i = a, j = 1; j <= b; i --, j ++ )
{
up = (LL)up * i % mod;
up = (LL)up * qmi(j, mod - 2) % mod;//放在里面会超时
}
return up;
}
/*
int C(int a, int b)
{
if (a < b) return 0;
int down = 1, up = 1;
for (int i = a, j = 1; j <= b; i --, j ++ )
{
up = (LL)up * i % p;
down = (LL)down * j % p;
}
return (LL)up * qmi(down, p - 2) % p;
}
*/
int Lucas(int a, int b)
{
if(a < mod && b < mod)return C(a, b);
return (LL)C(a % mod, b % mod) * Lucas(a / mod, b / mod) % mod;
}
int main()
{
int T;
cin >> T;
while(T --){
int n, l, r;
cin >> n >> l >> r;
cout << (Lucas(r - l + n + 1, r - l + 1) - 1 + mod ) % mod << endl;
}
return 0;
}