Seive of Eratosthenes

This is an algorithm for finding all prime numbers up to some limit n. You start with a list of all the integers between 2 and n:

Then you take the first number as the first prime, and delete from the list all multiples of that prime:

Repeat with the next number still in the list:

And so on...

When you finish, you have gotten all the primes from the list.