To program the algorithm, we have an array of integers or boolean values. The array item A[i]
is equal to 1, if i
is a prime number, otherwise it is set to zero. Firstly, all array item are set to 1 (we suppose all numbers are prime numbers).
Then, array items with indecec of multiples 2, 3 , ... , are set to 0 in loop.
If some A[j]=0
, multiples of j were already set to 0.
We print indices of items that are set to 0 at the end.