const int MOD = 10007;
ll n, m;
ll qpow(ll x, ll n) {
ll res = 1;
while(n) {
if(n & 1)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
ll C(ll n, ll m) {
if(m > n)
return 0;
ll up = 1, down = 1;
for(ll i = n - m + 1; i <= n; ++i)
up = up * i % MOD;
for(ll i = 1; i <= m; ++i)
down = down * i % MOD;
return up * qpow(down, MOD - 2) % MOD;
}
ll Lucas(ll n, ll m) {
if(m > n)
return 0;
ll ans = 1;
for(; m; n /= MOD, m /= MOD)
ans = ans * C(n % MOD, m % MOD) % MOD;
return ans;
}
原文地址:https://www.cnblogs.com/Inko/p/11631626.html
时间: 2024-11-01 10:55:49