Bzoj 4403 Sequence Statistics Lucas theorem

Source: Internet
Author: User

4403: Sequence Statistics time limit:3 Sec Memory limit:128 MB
Description

Given three positive integers n, l, and R, the number of statistical lengths between 1 and N, and the size of the elements in the monotone non-descending sequence between L and R. Outputs the result of the answer to the 10^6+3 modulo.

Input

Enter the first line containing an integer t representing the number of data groups. 2nd to t+1 each line contains three integers N, l, and R,n, L, and r meaning title described.

Output

The output contains a T-line, and each line has a number that represents the result of the answer you have asked for the 106+3 modulo.

Sample Input21 4 52 4 5Sample Output25
HINT

Tips

The sample description shows that the 2 sequences that meet the criteria are [4] and [5].

"Data size and conventions" for 100% of data, 1≤n,l,r≤10^9,1≤t≤100, input data assurance l≤r.

Idea: Get a two-dimensional array that represents the number of the length of the end of L

L l+1 l+2 l+3 .... R

1 1 1 1 1 ... 1

2 1 2 3 4 ... R

.....

N 1 C (n,1) ... C ((r-l+1+n), N)

The answer is to take a matrix and, Sigma;

#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999#definePi 4*atan (1)//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;} ll f[1000010];voidInitintP) {//F[n] = n!f[0] =1;  for(intI=1; i<=p; ++i) F[i] = f[i-1] * I%p;} ll Pow_mod (ll A, ll X,intp) {LL ret=1;  while(x) {if(X &1) ret = ret * A%p; A= A * A%p; X>>=1; }    returnret;} ll Lucas (ll N, ll K, ll p) {//C (n, k)% pLL ret =1;  while(N &&k) {ll nn= N P, kk = kp; if(NN < KK)return 0;//INV (F[kk]) = F[kk] ^ (p-2)% pRET = RET * F[NN] * POW_MOD (F[KK] * F[nn-kk]% p, p-2, p)%p; N/= p, K/=p; }     returnret;}intMain () {ll x,y,z,i,t; Init (1000003); intT;    ll N,l,r; scanf ("%d",&T);  while(t--) {scanf ("%lld%lld%lld",&n,&l,&R);        ll N,k; ll ans=0; K=N; N= (r-l+1+N); Ans+=lucas (N,k,1000003); printf ("%lld\n", (ans+1000002)%1000003); }    return 0;}

Bzoj 4403 Sequence Statistics Lucas theorem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.