Prime numbers and the fundamental theorem of arithmetic
A prime number is a whole number greater than 1 whose only divisors are 1 and itself: 2, 3, 5, 7, 11, 13… A number with more divisors is composite. The number 1 is neither prime nor composite.
The fundamental theorem of arithmetic says every whole number greater than 1 can be written as a product of primes in exactly one way, apart from the order of the factors. That product is its prime factorization, usually written with exponents:
360 = 23 × 32 × 5
Prime factorizations make many other questions easy. Two numbers' greatest common factor and least common multiple can be read straight from them (see the GCF & LCM calculator), a fraction is in lowest terms when numerator and denominator share no prime, and a number is a perfect square exactly when every exponent is even.
How the calculator factors a number
By hand, the standard method is the division ladder: divide by the smallest prime that goes in evenly, write down the quotient, and repeat until you reach 1. For 360 the ladder is 360 ÷ 2 = 180, ÷ 2 = 90, ÷ 2 = 45, ÷ 3 = 15, ÷ 3 = 5, ÷ 5 = 1, so the prime factors are 2, 2, 2, 3, 3, 5. You only need to test primes up to the square root of what is left — if none divides it, the remainder is itself prime.
Trial division becomes slow for big numbers, so the calculator combines three algorithms, all with exact big-integer arithmetic:
- Trial division by small primes (up to 10,000) removes small factors quickly.
- The Miller–Rabin test with the first twelve primes as witnesses decides primality with certainty for every number below 3.3 × 1024.
- Pollard's rho algorithm (with Brent's cycle detection) splits what remains. It finds a factor p in roughly √p steps, so even a product of two 10-digit primes is split in about a second.
That is why the calculator accepts numbers up to 20 digits.
Divisors, divisor count and divisor sum
Once you know n = p₁^e₁ × p₂^e₂ × …, every divisor is obtained by choosing an exponent from 0 to eᵢ for each prime. That gives two neat formulas:
- Number of divisors: d(n) = (e₁ + 1)(e₂ + 1)…
- Sum of divisors: σ(n) = ∏ (pᵢ^(eᵢ+1) − 1) / (pᵢ − 1)
For 360 = 23 × 32 × 5: d = 4 × 3 × 2 = 24 divisors, and σ = 15 × 13 × 6 = 1,170.
Comparing the sum of the proper divisors (all divisors except n itself) with n classifies the number. If they are equal the number is perfect — 6 = 1 + 2 + 3 and 28 = 1 + 2 + 4 + 7 + 14. If the sum is larger the number is abundant (360 is: 810 > 360); if smaller, deficient (every prime is deficient).
Primes also underpin modern cryptography: RSA keys are products of two huge primes, and their security rests on how hard it is to reverse this calculation for numbers hundreds of digits long.
Frequently asked questions
Is 1 a prime number?
No. A prime must have exactly two different divisors, and 1 has only one. Excluding 1 is also what makes prime factorizations unique.
Is 2 the only even prime?
Yes. Every other even number is divisible by 2, so it has at least three divisors (1, 2 and itself).
How can I tell quickly if a number is divisible by 3?
Add its digits. If the digit sum is divisible by 3, so is the number; the same rule works for 9. For example 360 → 3 + 6 + 0 = 9, so 360 is divisible by both 3 and 9.
Why is there a 20-digit limit?
Factoring gets dramatically harder as numbers grow. Up to 20 digits every number factors in about a second in your browser; much larger numbers built from two big primes could take minutes or longer.
Last reviewed: