Factorization
Factorization refers to expressing an integer as a product of its prime factors. Efficient factorization algorithms have applications in cryptography and math.
Some common methods:
- Trial division - Test divisions by primes up to sqrt(n)
- Fermat’s factorization - Express n as difference of squares
- Pollard’s rho - Find factorization using random sequences
Java example - Trial division:
|
|
C++ example - Pollard’s rho:
|
|
Python example - Fermat’s factorization:
|
|
Factorization provides the fundamental primes comprising a composite number. Useful for many number theoretic algorithms.
Minimum Factorization
The minimum factorization of an integer n is the smallest prime number that divides n. It can be found efficiently and provides a useful primitive for many algorithms.
Some approaches:
- Try all primes up to √n
- Use smallest prime factor of n-1
- Wheel factorization
Java example:
|
|
C++ example:
|
|
Python example:
|
|
Finding the smallest prime factor quickly is useful as a subroutine in various algorithms like factorization and primality testing.