Online proof a lot, although not read ....
The main solution to the case of large combined number of modulus
Baidu Star 2016 1003
First push the formula, then Lucas.
P Very Large case 1e9+7
1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> - #defineCLC (A, B) memset (A,b,sizeof (a)) -#include <bits/stdc++.h> the Const intMAXN =20005; - Const intinf=0x3f3f3f3f; - Const DoublePi=acos (-1); -typedefLong LongLL; + using namespacestd; - ConstLL MOD = 1e9+7; + A ll Exp_mod (ll A, ll B, ll P) at { -LL res =1; - while(b! =0) - { - if(b&1) Res = (res * a)%p; -A = (a*a)%p; inb >>=1; - } to returnRes; + } - the ll Comb (ll A, ll B, ll P) * { $ if(A < b)return 0;Panax Notoginseng if(A = = b)return 1; - if(b > A) b = A-b; the +LL ans =1, CA =1, CB =1; A for(LL i =0; I < b; ++i) the { +CA = (CA * (a-i))%p; -CB = (CB * (b-i))%p; $ } $Ans = (ca*exp_mod (CB, P-2, p))%p; - returnans; - } the -LL Lucas (intNintMintp)Wuyi { theLL ans =1; - Wu while(n&&m&&ans) - { AboutAns = (Ans*comb (n%p, m%p, p))%p; $N/=p; -M/=p; - } - returnans; A } + the intMain () - { $ intN, M; the LL p; the while(~SCANF ("%d%d", &n, &m)) the { thep=MOD; -printf"%i64d\n", Lucas (n+m-4, M-2, p)); in } the return 0; the}
p at about 100000
HDU 3037
1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> - #defineCLC (A, B) memset (A,b,sizeof (a)) -#include <bits/stdc++.h> the Const intMAXN =20005; - Const intinf=0x3f3f3f3f; - Const DoublePi=acos (-1); -typedefLong LongLL; + using namespacestd; - //const LL MOD = 1e9+7; + A ll Powmod (ll a,ll b,ll MOD) { atLL ret=1; - while(b) { - if(b&1) ret= (ret*a)%MOD; -A= (a*a)%MOD; -b>>=1; - } in returnret; - } toLL fac[100005]; + ll Get_fact (ll p) { -fac[0]=1; the for(intI=1; i<=p;i++) *Fac[i]= (fac[i-1]*i)%p; $ }Panax Notoginseng ll Lucas (ll n,ll m,ll p) { -LL ret=1; the while(n&&m) { +LL a=n%p,b=m%p; A if(A<B)return 0; theRet= (Ret*fac[a]*powmod (fac[b]*fac[a-b]%p,p-2, p))%p; +N/=p; -M/=p; $ } $ returnret; - } - intMain () { the intT; -scanf"%d",&t);Wuyi while(t--){ the LL n,m,p; -scanf"%i64d%i64d%i64d",&n,&m,&p); Wu get_fact (p); -printf"%i64d\n", Lucas (n+m,m,p)); About } $ return 0; -}
--lucas theorem of number theory