Intermediate level

Prime numbers

A prime number has exactly two divisors: one and itself. Learn the definition, the sieve of Eratosthenes, prime factorisation, and the fundamental theorem of arithmetic.

Before you start

This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:

All formulas

  • Definition of a prime

    p is prime    p>1 and p has exactly 2 divisorsp \text{ is prime} \iff p > 1 \text{ and } p \text{ has exactly 2 divisors}

    its only divisors are 1 and itself

  • Fundamental theorem of arithmetic

    n=p1a1p2a2pkakn = p_1^{a_1} \cdot p_2^{a_2} \cdot \ldots \cdot p_k^{a_k}

    the prime factorisation is unique

  • Primality test

    n composite    pn:pnn \text{ composite} \implies \exists\, p \le \sqrt{n} : p \mid n

    divisors up to the square root are enough

  • GCD and LCM from factorisations

    gcd=pimin(ai,bi),lcm=pimax(ai,bi)\gcd = \prod p_i^{\min(a_i, b_i)}, \quad \operatorname{lcm} = \prod p_i^{\max(a_i, b_i)}

    lowest exponents for the GCD, highest for the LCM

A prime number is a natural number greater than 11 with exactly two divisors: one and itself. A number greater than 11 with more divisors is composite.

p is prime    p>1 and p has exactly 2 divisorsp \text{ is prime} \iff p > 1 \text{ and } p \text{ has exactly 2 divisors}

The list starts like this:

2,  3,  5,  7,  11,  13,  17,  19,  23,  29,  31,  372, \; 3, \; 5, \; 7, \; 11, \; 13, \; 17, \; 19, \; 23, \; 29, \; 31, \; 37 \ldots

Two edge cases are worth remembering separately. One is not prime — it has a single divisor. Two is prime, and it is the only even prime: every other even number is divisible by 22 and therefore has at least three divisors.

There are infinitely many primes — Euclid noticed that if the list were finite, the number equal to the product of all its entries plus 11 would be divisible by none of them.

The sieve of Eratosthenes

The oldest way to list primes: write the numbers from 22 to nn, then cross out the multiples of each number that survives. Only the primes remain.

For n=30n = 30: keep 22 and cross out 4,6,8,4, 6, 8, \ldots; keep 33 and cross out 9,15,21,279, 15, 21, 27; keep 55 and cross out 2525. Untouched are:

2,3,5,7,11,13,17,19,23,292, 3, 5, 7, 11, 13, 17, 19, 23, 29

The primality test — up to the square root

Testing a single number needs no sieve. It is enough to look for divisors up to the square root:

n composite    pn:pnn \text{ composite} \implies \exists\, p \le \sqrt{n} : p \mid n

Why? Because if n=abn = a \cdot b and both factors were larger than n\sqrt{n}, their product would exceed nn. The smaller factor therefore always sits below the square root.

Is 91 a prime number?

Prime factorisation

Every natural number greater than 11 can be written as a product of primes — and in only one way (up to the order of the factors). That is the fundamental theorem of arithmetic:

n=p1a1p2a2pkakn = p_1^{a_1} \cdot p_2^{a_2} \cdot \ldots \cdot p_k^{a_k}

Primes are the "atoms" of arithmetic: every number is built from them, and in exactly one way.

The factorisation comes from dividing by successive primes, smallest first:

Factorise 84 into primes

GCD and LCM from factorisations

Factorisation gives a third way — next to listing divisors and the Euclidean algorithm — to compute the GCD and the LCM. Take the exponents of the shared primes: the lowest ones for the GCD, the highest ones for the LCM.

gcd=pimin(ai,bi),lcm=pimax(ai,bi)\gcd = \prod p_i^{\min(a_i, b_i)}, \qquad \operatorname{lcm} = \prod p_i^{\max(a_i, b_i)}
Compute the GCD and the LCM of 84 and 90 from their factorisations

Practice

Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.

Exercise 1 of 8Score: 0
smallest prime factor of 10

Common mistakes

  • Counting 11 as prime — it has one divisor, and the definition asks for exactly two.
  • Ruling 22 out for being even — being even is no obstacle; 22 is prime, just the only even one.
  • Testing divisors all the way up to nn — up to n\sqrt{n} is enough, which cuts the work many times over.
  • Leaving a composite number in the factorisation84=42184 = 4 \cdot 21 is not a prime factorisation yet; carry on to 22372^2 \cdot 3 \cdot 7.

Formula card

Topic: Prime numbers

  • Definition of a prime

    p is prime    p>1 and p has exactly 2 divisorsp \text{ is prime} \iff p > 1 \text{ and } p \text{ has exactly 2 divisors}

    its only divisors are 1 and itself

  • Fundamental theorem of arithmetic

    n=p1a1p2a2pkakn = p_1^{a_1} \cdot p_2^{a_2} \cdot \ldots \cdot p_k^{a_k}

    the prime factorisation is unique

  • Primality test

    n composite    pn:pnn \text{ composite} \implies \exists\, p \le \sqrt{n} : p \mid n

    divisors up to the square root are enough

  • GCD and LCM from factorisations

    gcd=pimin(ai,bi),lcm=pimax(ai,bi)\gcd = \prod p_i^{\min(a_i, b_i)}, \quad \operatorname{lcm} = \prod p_i^{\max(a_i, b_i)}

    lowest exponents for the GCD, highest for the LCM

Frequently asked questions

Related articles