Factorize any number into primes, check primality with Miller-Rabin test, calculate GCD and LCM, find Euler's totient, list prime numbers in a range and perform modular arithmetic.
Prime factorization is the process of expressing a positive integer as a product of its prime factors. Every composite number can be broken down into prime numbers that multiply together to give the original number. For example, 360 = 2³ × 3² × 5.
To find the prime factorization of a number n, we repeatedly divide by the smallest prime factor (starting from 2) until the quotient is 1. The collection of all prime divisors (with their multiplicities) is the prime factorization.
The Fundamental Theorem of Arithmetic states that every integer greater than 1 either is itself a prime, or can be represented as a product of prime numbers, and that this representation is unique up to the order of the factors. This uniqueness makes prime factorization a cornerstone of number theory.
Euler's totient function φ(n) counts the number of positive integers up to n that are relatively prime to n (i.e., GCD(k, n) = 1 for 1 ≤ k ≤ n). It is a fundamental function in number theory with deep connections to RSA cryptography.
For n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ: φ(n) = n × ∏(1 − 1/pᵢ)
| n | Coprime integers | φ(n) |
|---|---|---|
| 1 | {1} | 1 |
| 2 | {1} | 1 |
| 3 | {1, 2} | 2 |
| 4 | {1, 3} | 2 |
| 5 | {1, 2, 3, 4} | 4 |
| 6 | {1, 5} | 2 |
| 7 | {1, 2, 3, 4, 5, 6} | 6 |
| 8 | {1, 3, 5, 7} | 4 |
| 9 | {1, 2, 4, 5, 7, 8} | 6 |
| 10 | {1, 3, 7, 9} | 4 |
| 11 | {1,2,3,4,5,6,7,8,9,10} | 10 |
| 12 | {1, 5, 7, 11} | 4 |