Problem

Write a Primes program that finds prime numbers using the Sieve of Eratosthenes, an algori...

Write a Primes program that finds prime numbers using the Sieve of Eratosthenes, an algorithm devised by a Greek mathematician of the same name who lived in the third century BC. The algorithm finds all prime numbers up to some maximum value n, as described by the following pseudocode:

create a queue of numbers to process.fill the queue with the integers 2 through n inclusive.create an empty result queue to store primes.

repeat the following steps:	obtain the next prime p by removing the first value		from the queue of numbers.	put p into the result queue of primes.	loop through the queue of numbers,		eliminating all numbers that are divisible by p.while (p is less than the square root of n).

all remaining values in the numbers queue are prime,so transfer them to the result primes queue.

Wikipedia has a nice description and animation of this algorithm in action: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT