Chapter 8: Problem 4
Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer \(n\). This function will compute all prime numbers up to \(n\). First insert all numbers from 1 to \(n\) into a set. Then erase all multiples of 2 (except 2); that is, \(4,6,8,10,12 \ldots .\) Erase all multiples of 3 , that is, \(6,9,12,15, \ldots\). Go up to \(\sqrt{n}\). The remaining numbers are all primes.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.