How Prime Factorization Works

Prime factorization breaks any integer greater than 1 into a unique product of prime numbers. This page explains the trial division method, factor trees, and how factorization is used to compute GCD, LCM, and is foundational to modern cryptography.

The Fundamental Theorem of Arithmetic

Every integer greater than 1 is either a prime number itself, or can be expressed as a unique product of prime numbers. This uniqueness (up to ordering) is guaranteed by the Fundamental Theorem of Arithmetic.

The factorization is unique. For example, 12 = 2² × 3 is the only way to express 12 as a product of primes — there is no other combination.

Trial Division Method

Trial division is the simplest factorization algorithm. Divide the number by increasing integers starting from 2, collecting each successful divisor as a prime factor.

  1. Set d = 2 (the smallest prime).
  2. While d² ≤ n: if d divides n, record d as a factor and replace n with n ÷ d. Repeat until d no longer divides n, then increment d.
  3. If n > 1 after the loop, n itself is a prime factor.

Worked Example: Factorize 360

StepNumberDivisorQuotient
13602180
2180290
390245
445315
51535
6551

Worked Example: Factorize 1001

1001 looks large but factors quickly. We test divisors up to √1001 ≈ 31.6.

StepNumberDivisorQuotient
110017143
21431113
313131

Counting Divisors

Given the prime factorization n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ, the total number of positive divisors is:

For 360 = 2³ × 3² × 5¹: τ(360) = (3+1)(2+1)(1+1) = 4 × 3 × 2 = 24 divisors.

GCD and LCM from Prime Factorization

For two numbers a and b with known prime factorizations:

  • GCD(a, b): for each prime, take the smaller (minimum) exponent.
  • LCM(a, b): for each prime, take the larger (maximum) exponent.

Example: a = 360 = 2³ × 3² × 5, b = 756 = 2² × 3³ × 7

Why Does This Matter? Cryptography

RSA encryption multiplies two large prime numbers p and q to produce n = p × q. Multiplying them takes microseconds. Reversing the process — recovering p and q from n — takes classical computers an astronomical amount of time when p and q are hundreds of digits long. This one-way difficulty is the mathematical foundation of public-key cryptography.

No efficient classical algorithm for general integer factorization is known. The best known method (General Number Field Sieve) still runs in sub-exponential but super-polynomial time. Shor's quantum algorithm could factor in polynomial time, but practical quantum computers of sufficient size do not yet exist.

Frequently Asked Questions

Is the prime factorization of every number unique?

Yes. The Fundamental Theorem of Arithmetic guarantees that every integer greater than 1 has exactly one prime factorization, regardless of the order in which you find the factors.

What is the prime factorization of a prime number?

A prime number p is its own factorization: p = p¹. It has no divisors other than 1 and itself, so there are no smaller prime factors to extract.

How does trial division work for very large numbers?

Trial division tests each candidate divisor d from 2 up to √n. If no divisor is found, the number is prime. The key insight is that if n has a factor larger than √n, it must have a corresponding factor smaller than √n — so checking up to √n is sufficient.

What is a factor tree?

A factor tree is a visual diagram that starts with a number at the top and branches into two factors at each step, continuing until all branches end in prime numbers. It produces the same result as trial division but is easier to draw by hand for small numbers.

What makes a number a perfect square based on its factorization?

A number is a perfect square if and only if every prime factor has an even exponent in its factorization. For example, 36 = 2² × 3² is a perfect square (both exponents are even), while 72 = 2³ × 3² is not (the exponent of 2 is odd).