标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 typedef long long LL; 6 const int p = 1e9 + 7; 7 LL quick_mod(LL a, LL b) { 8 LL ans = 1; 9 a %= p; 10 while(b) { 11 if(b & 1) { 12 ans = ans * a % p; 13 b--; 14 } 15 b >>= 1; 16 a = a * a % p; 17 } 18 return ans; 19 } 20 21 LL C(LL n, LL m) { 22 if(m > n) return 0; 23 LL ans = 1; 24 for(int i=1; i<=m; i++) { 25 LL a = (n + i - m) % p; 26 LL b = i % p; 27 ans = ans * (a * quick_mod(b, p-2) % p) % p; 28 } 29 return ans; 30 } 31 LL Lucas(LL n, LL m) { 32 if(m == 0) return 1; 33 return C(n % p, m % p) * Lucas(n / p, m / p) % p; 34 } 35 int main() { 36 int k, T, n, m; 37 scanf("%d", &T); 38 while(T--){ 39 scanf("%d%d%d", &n, &m, &k); 40 if(m == 1) printf("%d\n", n); 41 else { 42 printf("%d\n", n*Lucas(n-k*m-1, m-1)%p*quick_mod(m, p-2)%p); 43 } 44 } 45 return 0; 46 }
看了看别人交的代码,发现自己的好慢
icpc2016沈阳网络赛1003hannnnah_j’s Biological Test组合数模板题
标签:
原文地址:http://www.cnblogs.com/cshg/p/5887279.html