1312. 序列统计 - AcWing题库
L~R范围可以等同于0~R-L范围
相当于在R-L+1个数中选出k个数
令
则变为
相当于在R-L+k个数中选出k个数
需要计算
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;const int mod = 1e6 + 3;int qmi(int a, int k)
{int res = 1;while(k){if(k & 1)res = (ll)res * a % mod;a = (ll)a * a % mod;k >>= 1;}return res;
}int C(int a, int b)
{if (a < b) return 0;int fz = 1, fm = 1;for(int i = a, j = 1; j <= b; i --, j ++){fz = (ll)fz * i % mod;fm = (ll)fm * j % mod;}return (ll)fz * qmi(fm, mod - 2) % mod;
}int lucas(int a, int b)
{if(a < mod && b < mod)return C(a, b);return (ll)lucas(a / mod, b / mod) * lucas(a % mod, b % mod) % mod;
}int main()
{IOSint _;cin >> _;while(_ --){int n, l, r;cin >> n >> l >> r;cout << (lucas(r - l + n + 1, r - l + 1) - 1 + mod) % mod << endl;}return 0;
}