Essentially we have two ways to solve this problem:

  • ATesting in order one by one if the number is prime or not. And if it is write it.
  • BStore all numbers and discard the multiples of primes we know. (Sieve of Eratosthenes).

 

WHAT IS MORE CONVENIENT?

A OPTION

Disadvantages: We have to calculate if the number is prime or not for each number.

Advantages: We don’t need store the numbers.

B OPTION

Disadvantages: We need store all numbers (although We can drastically reduce)

Advantages: It’s more faster because the primes are not calculated.

We Choose option B because it is much easier store than process and also can greatly reduce the numbers we store considering that we can eliminate half of the numbers if we eliminate the even numbers in the list, and a third if we eliminate multiples of 3 and so on, while we can keep indexing properly.