You can use the sieve of Eratosthenes
You create a list L1 of numbers from 2 to N.
You add the first number N of this list in the list of prime numbers LP, you clean the list L1 of all multiples of N and you recurse with the new list L1 and the new list LP.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.