标签:
1 LL quick_mod(LL a, LL b) 2 { 3 LL ans = 1; 4 a %= p; 5 while(b) 6 { 7 if(b & 1) 8 { 9 ans = ans * a % p; 10 b--; 11 } 12 b >>= 1; 13 a = a * a % p; 14 } 15 return ans; 16 } 17 18 LL C(LL n, LL m) 19 { 20 if(m > n) return 0; 21 LL ans = 1; 22 for(int i=1; i<=m; i++) 23 { 24 LL a = (n + i - m) % p; 25 LL b = i % p; 26 ans = ans * (a * quick_mod(b, p-2) % p) % p; 27 } 28 return ans; 29 } 30 31 LL Lucas(LL n, LL m) 32 { 33 if(m == 0) return 1; 34 return C(n % p, m % p) * Lucas(n / p, m / p) % p; 35 }
标签:
原文地址:http://www.cnblogs.com/pblr/p/5719619.html