【BZOJ2982】combination(Lucas定理)
题意:求C(n,m)
n,m<=200000000
思路:c(n,m)=c(n mod mo,m mod mo)*c(n div mo,m div mo) mod mo (n>=mo或m>=mo)
c(x,y)=0 (x<y)
c(n,m)=fac[n]*exf[m]*exf[n-m] (n,m<mo)
1 const mo=10007; 2 var exf,fac:array[0..1000000]of longint; 3 n,i,x,y:longint; 4 5 function c(n,m:longint):longint; 6 begin 7 if n<m then exit(0); 8 if (n<mo)and(m<mo) then exit(fac[n]*exf[m] mod mo*exf[n-m] mod mo); 9 exit(c(n mod mo,m mod mo)*c(n div mo,m div mo) mod mo); 10 end; 11 12 begin 13 assign(input,'bzoj2982.in'); reset(input); 14 assign(output,'bzoj2982.out'); rewrite(output); 15 readln(n); 16 exf[0]:=1; exf[1]:=1; fac[0]:=1; fac[1]:=1; 17 for i:=2 to 1000000 do 18 begin 19 exf[i]:=exf[mo mod i]*(mo-mo div i) mod mo; 20 fac[i]:=fac[i-1]*i mod mo; 21 end; 22 for i:=1 to 1000000 do exf[i]:=exf[i-1]*exf[i] mod mo; 23 24 for i:=1 to n do 25 begin 26 readln(x,y); 27 writeln(c(x,y)); 28 end; 29 close(input); 30 close(output); 31 end.
null