Home / Math / Prime Factorization Calculator
Prime Factorization Calculator
Enter a whole number from 2 to 1,000,000,000,000 and see it written as a product of primes, together with how many divisors it has, their sum and, for smaller numbers, the full list.
How the factorization is found
The fundamental theorem of arithmetic says every whole number greater than 1 is either prime or can be written as a product of primes in exactly one way, apart from the order of the factors. This page finds that product by trial division. It divides out every factor of 2 first, then tries the odd numbers 3, 5, 7 and so on, dividing each one out as many times as it fits.
The search only has to run while the trial divisor squared is no larger than what remains. If a number has a factor bigger than its square root, the matching cofactor is smaller than the square root and would already have been found. Whatever is left above 1 at the end must itself be prime. For a number near one trillion that means at most about half a million trial divisions, which a browser finishes almost instantly.
Counting and summing divisors from the exponents
Once the number is written as pa × qb × rc …, its divisors can be counted without listing them. Each divisor chooses an exponent for every prime from zero up to that prime's own exponent, so the count is (a + 1)(b + 1)(c + 1) …. For 360 = 23 × 32 × 5 the count is 4 × 3 × 2 = 24.
The sum of the divisors multiplies the matching geometric sums: (1 + p + … + pa)(1 + q + … + qb) …. For 360 that is 15 × 13 × 6 = 1,170. A number is a perfect square exactly when every exponent is even, which is also exactly when it has an odd number of divisors.
What prime factors are used for
- Fractions. Cancelling common primes in the numerator and denominator reduces a fraction to lowest terms.
- GCF and LCM. The greatest common factor takes the smaller exponent of each shared prime, and the least common multiple takes the larger. See the GCF calculator and the LCM calculator.
- Simplifying roots. A square root simplifies by pulling out every prime that appears at least twice, so 360 gives 6√10.
- Checking primality. A result with a single prime to the first power means the input was prime. A dedicated prime number checker handles much larger inputs.
Limits and common mistakes
The number 1 is not prime and has no prime factorization, because counting it would break the uniqueness in the theorem above. Every factor in the output is prime, so a composite such as 4 or 6 never appears as a factor. Write repeated primes as exponents: 2 × 2 × 2 is 23.
This page accepts whole numbers up to 1012, where trial division is quick and every intermediate value is exact in standard double-precision arithmetic. Factoring very large numbers is a hard problem in general, which is why public-key cryptography relies on products of two huge primes. For a number with hundreds of digits, specialised software and far more time are needed.
Worked example
Factor 360, a number with many divisors, and see how the exponents determine how many divisors it has.
Inputs
| Whole number to factor | 360 |
|---|
Result
The largest prime factor is 5.
| Prime factorization | 2^3 × 3^2 × 5 |
|---|---|
| Distinct prime factors | 3 |
| Prime factors counted with repeats | 6 |
| Number of divisors | 24 |
| Sum of divisors | 1,170 |
| Perfect square | No |
| All divisors | 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360 |
Prime factor table
| Prime | Exponent | Prime power |
|---|---|---|
| 2 | 3 | 8 |
| 3 | 2 | 9 |
| 5 | 1 | 5 |
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
What is prime factorization?
It is writing a whole number greater than 1 as a product of prime numbers. For example, 360 equals 2 × 2 × 2 × 3 × 3 × 5, which is written 2^3 × 3^2 × 5.
Is the prime factorization of a number unique?
Yes. Apart from the order of the factors, every whole number greater than 1 has exactly one prime factorization. This is the fundamental theorem of arithmetic.
How many divisors does a number have?
Add one to each exponent in the prime factorization and multiply the results. For 360 with exponents 3, 2 and 1, the count is 4 × 3 × 2 = 24 divisors.
Why is 1 not a prime number?
A prime must have exactly two distinct divisors, and 1 has only one. Treating 1 as prime would also destroy the uniqueness of factorization, since extra factors of 1 could be added freely.
What is the largest number this calculator can factor?
It accepts whole numbers up to 1,000,000,000,000. Within that range trial division is fast and every value is represented exactly by the browser.
Related calculators
References and sources
- Hardy, G. H. and Wright, E. M., An Introduction to the Theory of Numbers: the fundamental theorem of arithmetic and divisor functions.
- Euclid, Elements Book VII and IX: early statements of factorization into primes.