Lists Samuel Marateck © 2010
The Sieve of Eratosthenes
Place a 0 in all slots X = 26*[0]
Place 0’s in all slots
Start with 2 for j in range(2, √25):
Start with 2 for j in range(2, √25): if x[j] == 0:
Start with 2 for j in range(2, √25): if x[j] == 0: index = 2*j
Start with the 2 slot
for j in range(2, √25): if x[j] == 0: index = 2*j while index < 25: x[index] = 1
Place a 1 in the 4 slot
for j in range(2, √25): if x[j] == 0: index = 2*j while index < 25: x[index] = 1 index = index + j
Then in the 6 slot
Continue
Place 1’s in all multiples of 2 slots
Since there is a 0 in the 3 slot, 3 is prime
There is a 1 already in the 6 slot
Place a 1 in the 9 slot
The 12 slot already has a
Then a 1 in the 15 slot
Then a 1 in the 21 slot
Now there is a 1 in all multiple of 3 slots
Skip the 4 slot since it has a
There is a 0 in the 5 slot, so 5 is prime
Place a 1 in multiple of 5 slots
The only non-zero slot is
Since √25 is 5 we stop here
Starting with 2, all the slots with 0’s are prime numbers