Prints all primes smaller or equal to a limit n
Efficient of when n <= 10,000,000
Algorithm
- Assume all numbers from
2
ton
are unmarked - Mark the number 2 as prime, then mark all multiples of 2 as composite
- The next unmarked number from 2 is prime (3 in this case), then mark all multiples of 3 that are currently unmarked as composite
- Repeat the process with all subsequent unmarked numbers