Combination sequence count statistics ------

Given three positive integer N, L, RN, L, R, statistics length is between 11 to NN, LL element size are the number did not fall monotonically between the RR sequence.
The answer to output 106 + 3106 + 3 modulo results.
Input format
input of the first row contains an integer TT, represents the number of data sets.
Second through T + 1T + 1 lines contains three integers N, L, RN, L, R.
Output format
output contains TT lines, each having a number indicating the obtained result you answer to 106 + 3106 + 3 modulo.
Data range
1≤N, L, R≤1091≤N, L, R≤109,

1≤T≤1001≤T≤100,

Input data to ensure L≤RL≤R.
Sample input:
2
. 1. 5. 4
2. 4. 5

Output Sample:
2
. 5

Sample explained
for the first set of input, two sequences satisfying the condition of {4}, {5}.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int p = 1000003; 
int qmi(int a, int k){
 int res = 1;
 while(k){
  if(k & 1)   res = (LL)res * a % p;
  a = (LL)a * a % p;
  k >>= 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 % p;
  down = (LL)down * j % p;
 }
 return (LL)up * qmi(down, p - 2) % p;
}
int Lucas(int a, int b){
 if (a < p && b < p)   return C(a, b);
 return (LL)Lucas(a / p, b / p) * C(a % p, b % p) % p;
}
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) + p - 1) % p << endl;
 }
  return 0;
}
Published 106 original articles · won praise 67 · views 5402

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/105084683
Recommended