Theorem [Lucas] Luo Gu P4345

In midday lazy to write about water issues is an excellent thing []

\(\sum\limits_{i=0}^k\binom{n}{i}\; mod \;2333\)

Look so small a modulus sure Lucas []

The Lucas theorem: \ (\ {n-Binom} {K} = \ {n-Binom / MOD {K} / * MOD} \ {n-Binom% MOD% MOD K} {} \)

Then be happy divisible block wave [], and then a wave of happiness merger of similar items []

\(f(n,k)=\sum\limits_{i=0}^k \binom{n}{i}\)

于是有\ (f (n, k) = f (n / v, k / mod-1) * f (n \% v, v-1) + \ sum \ limits_ {i = 0} ^ {k \% v} \ {n binom / v {k} / v} \ {n binom \%} {v i} \)

Recursive processing on a wave of pleasures []

[Saying why I use the memory map of T will not have to, ah [A]]

#include <bits/stdc++.h>
#define ll long long
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define mod 2333
using namespace std;
int pre[2334][2334],C[2334][2334];
int Lucas(ll x,ll y){
    if(!y) return 1;
    if(x<y) return 0;
    if(x==y) return 1;
    return C[x%mod][y%mod]*Lucas(x/mod,y/mod)%mod;
}
int F(ll n,ll k){
    if(k<0 || n<0) return 0;
    if(k<mod && n<mod) return pre[n][k];
    return (1ll*Lucas(n/mod,k/mod)*pre[n%mod][k%mod]%mod+1ll*F(n/mod,k/mod-1)*pre[n%mod][mod-1]%mod)%mod;
}
int main(){
    ll n,k;int T;
    For(i,0,mod) C[i][0]=1;
    For(i,1,mod) For(j,1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    For(i,0,mod) pre[i][0]=1;
    For(i,0,mod) For(j,1,mod-1) pre[i][j]=(pre[i][j-1]+C[i][j])%mod;
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld",&n,&k);
        printf("%d\n",F(n,k));
    }
}

Guess you like

Origin www.cnblogs.com/PsychicBoom/p/11966212.html