HomeMath › Prime Factorization Calculator

Prime Factorization Calculator

Decomposes an integer into its prime factors by trial division, tests primality, and derives the number and sum of its divisors from the exponents.

When to use

You need the prime factors of an integer up to 10^12, want to know whether it is prime, or need its divisor count.

Do not use when: You need the GCD or LCM of several numbers (use gcd-lcm) or factorials and binomial coefficients (use factorial, combinations-permutations).

Formula

n = p₁^k₁ × p₂^k₂ × … (trial division by 2, then odd numbers up to √n); τ(n) = Π (kᵢ + 1); σ(n) = Π (pᵢ^(kᵢ+1) − 1) / (pᵢ − 1)

Inputs

ParameterTypeUnitRequiredDescription
nintegeryesInteger to factor, from 2 to 1,000,000,000,000. Range: ≥ 2, ≤ 1000000000000

Outputs

OutputTypeUnitDescription
is_primebooleantrue when n has no divisors other than 1 and itself.
factorsnumber_listPrime factors in ascending order with repetition, e.g. [2, 2, 2, 3, 3, 5].
factorizationstringPrime-power form, e.g. '2^3 × 3^2 × 5'.
distinct_primesnumber_listEach prime factor once.
divisor_countintegerτ(n) = Π (kᵢ + 1) over the exponents kᵢ of the factorization.
sum_of_divisorsintegerσ(n) = Π (1 + pᵢ + pᵢ² + … + pᵢ^kᵢ), including 1 and n.

Example

360: {"n":360}{"is_prime":false,"factors":[2,2,2,3,3,5],"factorization":"2^3 × 3^2 × 5","distinct_primes":[2,3,5],"divisor_count":24,"sum_of_divisors":1170}

97: {"n":97}{"is_prime":true,"factors":[97],"factorization":"97","divisor_count":2,"sum_of_divisors":98}

GET https://tttkmbb.com/api/v1/calculate/prime-factorization?n=360

Machine access

Sources

FAQ

Why is 1 not accepted?

1 is neither prime nor composite and has an empty factorization, so the input must be at least 2.

How fast is this for large numbers?

Trial division needs at most about 500,000 divisions for n near 10^12, which takes a few milliseconds; larger inputs are rejected.

Related calculators