Skip to content
AZ Tools

Prime Factorization · GCD · LCM

Factor an integer into primes, list all divisors, and compute GCD and LCM of two numbers. Handles values up to ~10¹².

GCD (greatest common divisor)

36

LCM (least common multiple)

2520

360

Prime factorization

2^3 × 3^2 × 5

Divisors (24)

1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360

252

Prime factorization

2^2 × 3^2 × 7

Divisors (18)

1, 2, 3, 4, 6, 7, 9, 12, 14, 18, 21, 28, 36, 42, 63, 84, 126, 252

Trial division up to √n. Fast for inputs up to ~10¹². Divisor scan is skipped above 10⁹ to stay snappy.

How to use

  1. Enter a number in field A for factorization, divisors, and primality.
  2. Add a second number in field B to also compute GCD and LCM.
  3. Copy the factorization or read the divisor list. Divisor list capped at first 200 for very composite numbers.

About this tool

Show

Enter one or two positive integers. For each: the prime factorization in p^e × q^f form, every divisor, and whether the number itself is prime. Enter both and you also get GCD (greatest common divisor — useful for reducing fractions) and LCM (least common multiple — useful for finding a common period). Trial division up to √n is fast enough for numbers up to ~10¹² and runs entirely in your browser.

The square-root bound is what makes trial division practical rather than hopeless. A composite number always has a factor at or below its square root, so once the trial passes √n without a hit the number is prime and there is nothing left to check. That turns a search through a trillion candidates into a search through a million, which a browser does in a moment.

It still scales with the square root, and that is the ceiling. Every extra pair of digits multiplies the work by ten, so a number with twenty digits would need ten billion trials and a number of cryptographic size is out of reach by an unimaginable margin. That gap is not an implementation detail; it is the reason RSA works. Factoring a 2048-bit modulus is hard for the same arithmetic reason this tool stops at twelve digits.

The divisor list grows from the exponents rather than from the size of the number. Multiply each exponent plus one together and you have the count: 1024 is 2^10 and has eleven divisors, while 840 is far smaller and has thirty-two. A number with many small prime factors produces a long list, and a prime produces two.

GCD and LCM are related by the identity that their product equals the product of the two inputs, which is worth knowing because it means the LCM of two large numbers can overflow even when both inputs are comfortable. The pair 999999937 and 999999893 are both prime, so their LCM is their product, a number well past the largest integer a double can hold exactly.

Frequently asked questions

What's the largest input?

Up to about 10¹² (a trillion). Above that, trial division to √n starts getting slow, and past Number.MAX_SAFE_INTEGER (2⁵³ ≈ 9×10¹⁵) JavaScript loses integer precision. For bigger numbers you'd need BigInt and Pollard's rho.

Why no divisor list for large numbers?

We cap the divisor scan at n < 10⁹ to avoid pegging your CPU. The prime factorization still runs because it's O(√n) by the largest prime factor, often much less than n itself.

What's GCD good for?

Reducing fractions: 252/360 = ?. GCD(252, 360) = 36, so 252/360 = 7/10. Also used in cryptography (RSA), and to determine whether two cycles will ever align.

Is LCM(a, b) = a × b / GCD(a, b)?

Yes, always, for positive integers. We use exactly that identity. The intuition: LCM has every prime factor at its highest power across a and b; GCD has every prime factor at its lowest power; multiplying recovers a × b.

Related tools