Article From:https://www.cnblogs.com/kafuuchino/p/9906626.html

## Description

LMZYesnA different base friend, he chooses every night.mCarry out[River crab]，And it requires different choices every night. thatLMZHow many nights can it last? Of course,LMZIn one year10007God, so he wants to know the answer.mod 10007The value.(1<=m<=n<=200,000,000)

## Input

The first line is an integert，ExpresstGroup data.(t<=200)
NexttTwo integers per rown, m，For example.

## Output

TLines, one number per line, for the uuuuuuuuuuuuC(n, m) mod 10007The answer.

4
5 1
5 2
7 3
4 2

## Sample Output

5
10
35
6

\$n,m\$So big, \$mod \$so small
Last naked \$Lucas \$
Solve.

``` 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #define re register
5 using namespace std;
6 int min(int a,int b){return a<b?a:b;}
7 const int p=1e4+7;
8 int t,n,m,fac[p+2];
9 int Pow(int x,int y){
10     int res=1;
11     for(;y;y>>=1,x=1ll*x*x%p)
12         if(y&1) res=1ll*res*x%p;
13     return res;
14 }
15 int C(int a,int b){
16     return a<b?0:1ll*fac[a]*Pow(fac[b],p-2)%p*Pow(fac[a-b],p-2)%p;
17 }
18 int lucas(int a,int b){
19     return b?1ll*lucas(a/p,b/p)%p*C(a%p,b%p)%p:1;
20 }
21 int main(){
22     scanf("%d",&t); fac[0]=1;
23     for(int i=1;i<=p;++i) fac[i]=1ll*fac[i-1]*i%p;
24     while(t--){
25         scanf("%d%d",&n,&m);
26         printf("%d\n",lucas(n,min(m,n-m)));
27     }return 0;
28 }```

View Code