It works buy having a line of all the numbers from 2 to x then taking of all the multiples of 2 (except 2) then all the multiples of 3 then 5 (4 was taken of when the multiples of 2 where removed) so on so on.