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, and including, 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, ... . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to ?⎯⎯√n. The remaining numbers are all primes. Make sure that you use functions in your solution, including a main function. Define def sieveOfEratosthenes(n) that receives the maximum value and returns a list of all prime numbers less than or equal to this value in main() print the list of prime numbers.
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, and including, 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, ... . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to ?⎯⎯√n. The remaining numbers are all primes. Make sure that you use functions in your solution, including a main function. Define def sieveOfEratosthenes(n) that receives the maximum value and returns a list of all prime numbers less than or equal to this value in main() print the list of prime numbers.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 9SA
Related questions
Question
- 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, and including, 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, ... .
- Erase all multiples of 3, that is, 6, 9, 12, 15, ... .
- Go up to ?⎯⎯√n.
- The remaining numbers are all primes.
- Make sure that you use functions in your solution, including a main function.
- Define def sieveOfEratosthenes(n) that receives the maximum value and returns a list of all prime numbers less than or equal to this value
- in main() print the list of prime numbers.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning