How to use it
Enter a whole number from 2 to 1,000,000,000,000,000,000 (1018). Commas as thousands separators are fine. The answer gives the factorization in exponent form and written out in full, the number of distinct primes, the number of divisors, and whether the number is prime.
The method
Every whole number greater than 1 is either prime or a product of primes in exactly one way, apart from the order of the factors (the fundamental theorem of arithmetic). The calculator finds that product in three stages:
- Trial division by 2 and then by odd numbers up to 10,000 removes all small factors.
- Whatever is left is checked with a deterministic Miller–Rabin test using the first 13 primes (2 to 41) as bases. Below about 3.3 × 1024 this set of bases is proven to give the right answer, so the result is certain, not merely probable.
- If the remainder is composite, Pollard’s rho method (in Brent’s variant) splits it, and each part goes back through the test.
number of divisors = (e₁ + 1) × (e₂ + 1) × … × (ek + 1)p — the distinct primes; e — their exponents
For composite numbers up to 1012, the working is shown as a division ladder: divide by the smallest prime factor, repeat with the quotient, and stop at 1.
Worked examples
360
Given: n = 360
- 360 ÷ 2 = 180
- 180 ÷ 2 = 90
- 90 ÷ 2 = 45
- 45 ÷ 3 = 15
- 15 ÷ 3 = 5
- 5 ÷ 5 = 1
So 360 = 2 × 2 × 2 × 3 × 3 × 5 = 23 × 32 × 5. It has 3 distinct prime factors and (3 + 1) × (2 + 1) × (1 + 1) = 24 divisors, counting 1 and 360.
A 12-digit number
Given: n = 600,851,475,143
The ladder divides by 71, then 839, then 1,471, leaving 6,857, which is prime: 600,851,475,143 = 71 × 839 × 1,471 × 6,857. Four distinct primes, each to the power 1, give 2 × 2 × 2 × 2 = 16 divisors.
Is 1,000,000,007 prime?
Given: n = 1,000,000,007
Yes: its only divisors are 1 and itself. For a prime, the calculator describes the method instead of showing a ladder, since there is nothing to divide out.
Limits and conventions
- 0 and 1 are not accepted. 1 is neither prime nor composite and has no prime factors, and every prime divides 0.
- The upper limit is 1018 itself: 1018 = 218 × 518, with 19 × 19 = 361 divisors. Anything larger is rejected.
- Negative numbers and decimals are not accepted. To factor −360, factor 360 and put −1 in front.
- The divisor count includes 1 and the number itself; the divisors are counted, not listed.
Prime factorizations also give the greatest common factor and the least common multiple of several numbers, and they simplify square roots: 360 = 62 × 10, so √360 = 6√10.
Questions
Why is 1 not a prime number?
A prime has exactly two divisors, and 1 has only one. Excluding 1 is also what keeps factorizations unique: if 1 counted as prime, 6 could be written as 2 × 3, 1 × 2 × 3, 1 × 1 × 2 × 3 and so on.
How can the calculator be sure a large number is prime?
The Miller–Rabin test with a fixed set of bases is deterministic below a known bound. The first 13 primes as bases are proven sufficient for every number below about 3.3 × 1024, far above this calculator’s limit of 1018.
How do I list all the divisors?
Combine the prime powers in every possible way. For 360 = 23 × 32 × 5, each divisor is 2a × 3b × 5c with a from 0 to 3, b from 0 to 2 and c from 0 to 1 — 24 combinations in all.
Method & sources
- Deterministic bases and bounds for the primality test — Wikipedia: Miller–Rabin primality test
- The factoring method used for large factors — Wikipedia: Pollard’s rho algorithm