Topic links
The value of C (n, m)%p, N, m<=1e18, p = p1*p2*...pk. Pi is a prime number.
First, the value of the C (n, m)%PI is calculated, and then this is an equation of congruence. Solved by the Chinese remainder theorem.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#definell Long Longll a[ -], b[ -];voidExtend_euclid (ll A, ll B, ll &x, LL &y) { if(b = =0) {x=1; Y=0; return; } extend_euclid (b, a%b, x, y); LL TMP=x; X=y; Y= tmp-(A/b) *y;} LL Mul (ll A, ll N, ll MoD) {a= (a%mod+mod)%MoD; N= (n%mod+mod)%MoD; LL ret=0; while(n) {if(n&1) ret= (ret+a)%MoD; A= (a+a)%MoD; N>>=1; } returnret;} ll CRT (ll A[],ll m[],intN) {ll M=1; ll ans=0; for(intI=1; i<=n; i++) M*=M[i]; for(intI=1; i<=n; i++) {ll x, y; ll Mi= M/M[i]; Extend_euclid (Mi, M[i], x, y); Ans= (ans + mul (mul (Mi, X, M), A[i], m))%M; } return(ans+m)%M;} ll Pow (ll A, ll B, ll MoD) {LL ret=1; while(b) {if(b&1) ret = ret*a%MoD; A= a*a%MoD; b/=2; } returnret;} ll C (ll N, ll M, ll MoD) {ll a=1, B =1; for(inti =1; I <= m; i++) {b= b*i%MoD; A= A * (n-i+1)%MoD; } returnA*pow (b, mod-2, MoD)%MoD;} ll Lucas (ll N, ll M, ll MoD) {if(M = =0) return 1; returnLucas (N/mod, M/mod, MoD) *c (n%mod, M%mod, MoD)%MoD;}intMain () {ll t, N, M, K; CIN>>T; while(t--) {cin>>n>>m>>K; for(inti =1; I <= K; i++) {scanf ("%lld", &A[i]); } for(inti =1; I <= K; i++) {B[i]=Lucas (n, M, A[i]); } ll ans=CRT (b, a, k); cout<<ans<<Endl; } return 0;}
Hdu 5446 Unknown Treasure China remainder theorem +lucas