prime_fact

Function prime_fact 

Source
pub fn prime_fact(x: u64) -> Option<u64>
Expand description

Returns smallest divisible prime less than input, if any.

Returns None if input is a 0, 1 or a prime.

Used as building block for fast factorization or for sub-formulas e.g. product of two primes r * s.

Optimizes square number factorization using recursive call.

The most expensive part of this algorithm is iteration over odd numbers up to the square root. This search guaranteed to find a prime, because primes occur before any composite number divisible by primes.