4591: [Shoi2015] super-capable particle cannon • Change Time limit:10 Sec Memory limit:256 MB

submit:178 solved:70

[Submit] [Status] [Discuss] Description, inventor of the brain hole therapy & Super Particle cannon, SHTSC also disclosed his new invention: the super-particle cannon--a mysterious device that can emit more powerful particle flows. The super-energy particle cannon, compared to the super-energy particle cannon, has an essential lift in power. It has three parameters of n,k. It emits a particle stream with a power of C (n,k) mod 2333 to a location numbered 0 to K. Now SHTSC gives the parameters of his super-capable particle cannon, allowing you to ask for the sum of the power of the particle stream that it emits 2333.

Input first line an integer t. Represents the number of data groups. After the T line, two integers per line are n,k. Meaning title Polygon description. K<=n<=10^18,t<=10^5

The Outputt line is an integer that represents the sum of the power of the particle stream and the value of modulo 2333.

Sample Input1

5 5

Sample Output +HINT Source

by anonymous upload

Exercises

**Lucas theorem: C (n,k)%p= (c (n/p,k/p) *c (n%p,k%p))%p (P is prime)**

C (n,k)%2333=c (n/2333,k/2333) *c (n%2333,k%2333) In two parts of the consideration:set K=K1*2333+K2 (0≤K1,K2)

** 1. For the K1 section**C (n,0) ... C (n,2332)

=c (n/2333,0) *c (n%2333,0) +c (n/2333,0) *c (n%2333,1) +......+c (n/2333,0) *c (n%2333,2332) = C (n/2333,0) * (∑C (n%2333,i) ( 0≤i≤2332)) ==> 2,333 C (n,2333) ... C (n,4665)

=C (n/2333,1) *c (n%2333,0) +c (n/2333,1) *c (n%2333,1) +......+c (n/2333,1) *c (n%2333,2332) = C (n/2333,1) * (∑C (n%2333,i) ( 0≤i≤2332)) ==> 2,333 C (n,4666) ... C (n,6998)=C (n/2333,2) *c (n%2333,0) +c (n/2333,2) *c (n%2333,1) +......+c (n/2333,2) *c (n%2333,2332) = C (n/2333,2) * (∑C (n%2333,i) ( 0≤i≤2332)) ==> 2,333 C (n,6999) ... C (n,9331) =c (n/2333,3) *c (n%2333,0) +c (n/2333,3) *c (n%2333,1) +......+c (n/2333,3) *c (n%2333,2332) = C (n/2332,3) * (∑C (n%2333 , i) (0≤i≤2332)) ==> of 2,333 .....so the sum of the K1 part sum= (∑c (n%2333,i) (0≤i≤2332)) * (∑c (n/2333,j) (0≤j≤k1-1 ))

**2. For the K2 section**C (n,k1*2333) ... C (n,k)=c(N/2333,K1) *c (n%2333,0) +c (N/2333,K1) *c (n%2333,1) +......+c (N/2333,K1) *c (n%2333,k%2333) ==> k%2333+1 a =c (N/2333,K1) * (∑c (N%2333,i) (0≤i≤k%2333)) the above can be

**ans=**
**(∑c (n%2333,i) (0≤i≤2332)) * (∑c (N/2333,J) (0≤j≤k1-1)) +c (N/2333,K1) * (∑c (** n%2333,i) (0≤i≤k%2333)) preprocessing

**S (n,k) =∑c (n,i) (0≤i≤k)**, simplifying

**ans=**
**S (n%2333,2332) * (∑c (N/2333,J) (0≤j≤k1-1)) +c (N/2333,K1) *s (n%2333,k%2333)**because the n%2333 must be less than 2333, it can be represented by a two-dimensional array of S (n,k). Butn/2333 may be large in ∑c (n/2333,j) (0≤j≤k1-1) and cannot be stored in a two-dimensional array, so ∑c (n/2333,j) (0≤j≤k1-1) is not reduced to S (n/2333,k1-1). However, it can be found that ∑c (n/2333,j) (0≤j≤k1-1) is the same as the format ∑c (n,i) of the formula that requires the final answer, so it can be solved recursively. In addition, the C (N/2333,K1) in ans can be solved by Lucas theorem.

1#include <bits/stdc++.h>2 using namespacestd;3 #defineLL Long Long4 #defineMOD 23335LL jc[mod+Ten],c[mod+Ten][mod+Ten],s[mod+Ten][mod+Ten];6 LL Read ()7 {8LL s=0, fh=1;CharCh=GetChar ();9 while(ch<'0'|| Ch>'9'){if(ch=='-') fh=-1; ch=GetChar ();}Ten while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} One returns*fh; A } -LL MoD (ll k,ll K1) {returnK (K/K1) *K1;} - voidCLJC () the { -jc[0]=1LL; - for(intI=1; i<=mod;i++) Jc[i]=mod (jc[i-1]*i,mod); - } + voidClC () - { + inti,j; Ac[0][0]=1LL; at for(i=1; i<=mod;i++) - { -c[i][0]=c[i][i]=1LL; - for(j=1; j<i;j++) C[i][j]=mod (c[i-1][j]+c[i-1][j-1],mod); - } - for(i=0; i<=mod;i++) in { -s[i][0]=1LL; to for(j=1; j<=mod;j++) S[i][j]=mod (s[i][j-1]+c[i][j],mod); + } - } the ll KSM (ll bb,ll pp,ll KK) * { $LL s=1LL;Panax Notoginseng while(pp>0) - { the if(pp%2!=0) S=mod (s*bb,kk); +Pp/=2; ABb=mod (bb*bb,kk); the } + returns; - } $ ll Comb (ll n,ll m,ll p) $ { - if(m>n)return0LL; - if(m>n-m) m=n-m; the returnMoD (mod (jc[m]*jc[n-m],p), P-jc[n]*ksm2, P), p); - }Wuyi ll Lucas (ll n,ll m,ll p) the { - if(M==0LL)return1LL; Wu returnMoD/*Comb (mod (n,p), mod (m,p), p)*/C[n%p][m%p]*lucas (n/p,m/p,p), p); - } About ll Getans (ll n,ll m,ll p) $ { - if(M<0LL)return0LL; - returnMoD (mod (S[mod (n,2333)][2332]*getans (n/2333, m/2333-1, p), p) +mod (Lucas (n/2333, m/2333, p) *s[mod (n,2333)][mod (M,2333) (],p), p); - } A intMain () + { the LL t,n,k; - CLJC (); $ ClC (); thet=read (); the while(t--) the { theN=read (); k=read (); -printf"%lld\n", Getans (N,k,mod)); in } the fclose (stdin); the fclose (stdout); About return 0; the}

Bzoj 4591: [Shoi2015] super-energy particle cannon • Change number theory, Lucas theorem, permutation set