Prime factorization of n factorial -
how find prime factorization of n! when n large number(10^8)? efficient way this?
start finding primes $n$, perhaps sieve of eratosthenes. mark largest primes having exponent 1, way down (but not including) n/2. mark ones n/2 n/3 having exponent 2, , forth; continue until sqrt(n). @ point might compute each exponent separately, function (pseudocode):
factorial_exponent(n, p): n <- floor(n/p) let t = n while n >= p: n <- floor(n/p) t <- t + n return t you use function on primes instead of marking them in ranges suggested, though take little bit longer.
Comments
Post a Comment