【题目链接】
https://www.lydsy.com/JudgeOnline/problem.php?id=2982
【算法】
lucas定理
【代码】
#include<bits/stdc++.h> using namespace std; const int P = 10007; int n,m,T; int fac[P],inv[P]; inline int power(int a,int n) { int b = a,res = 1; while (n) { if (n & 1) res = 1ll * res * b % P; b = 1ll * b * b % P; n >>= 1; } return res; } inline void init() { int i; fac[0] = 1; for (i = 1; i < P; i++) fac[i] = 1ll * fac[i-1] * i % P; inv[P-1] = power(fac[P-1],P-2); for (i = P - 2; i >= 0; i--) inv[i] = 1ll * inv[i+1] * (i + 1) % P; } inline int c(int n,int m) { if (n < m) return 0; return 1ll * fac[n] * inv[m] % P * inv[n-m] % P; } inline int C(int n,int m) { if (m == 0) return 1; else return 1ll * C(n/P,m/P) * c(n%P,m%P) % P; } int main() { init(); scanf("%d",&T); while (T--) { scanf("%d%d",&n,&m); printf("%d ",C(n,m)); } return 0; }