wenbao与勒让德定理
何为勒让德定理?
在正数n!的素因子标准分解式中,素数p的指数记作
,则
求n的阶乘中可以快速算出它可以除的质数的最高次幂(即,最多可以除多少次)
http://codeforces.com/contest/711/problem/E
当然这里也用到了逆元,快速幂
1 #include <iostream> 2 using namespace std; 3 #define LL long long 4 const LL MOD = 1e6+3; 5 LL n, k, i, j, num = 0; 6 LL pow_mod(LL x, LL y){ 7 LL ans = 1; 8 while(y > 0){ 9 if(y & 1) ans = ans*x%MOD; 10 x = x*x%MOD; 11 y >>= 1; 12 } 13 return ans; 14 } 15 int main(){ 16 scanf("%lld%lld", &n, &k); 17 if(n < 64 && 1LL << n < k){ 18 printf("1 1\n"); 19 return 0; 20 } 21 for(i = k-1; i >= 1; i/=2){ 22 num += i/2; 23 } 24 LL N = pow_mod(2, n); 25 LL xx = pow_mod(2, num); 26 LL ni = pow_mod(xx, MOD-2), zi = 1; 27 for(i = 1; i <= k-1; ++i){ 28 zi = zi*(N-i)%MOD; 29 if(N == i) break; 30 } 31 zi = zi*ni%MOD; 32 LL mu = pow_mod(N, k-1)*ni%MOD; 33 printf("%lld %lld\n", (mu-zi+MOD)%MOD, mu); 34 return 0; 35 }
只有不断学习才能进步!