Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

JAVA PROGRAM (Please screenshot your output) SIEVE OF ERATOSTHENES The Greek mathematician Eratosthenes (276 BCE 195 BCE) devised a method of finding prime numbers, as

JAVA PROGRAM (Please screenshot your output)

SIEVE OF ERATOSTHENES

The Greek mathematician Eratosthenes (276 BCE 195 BCE) devised a method of finding prime numbers, as follows:

Create a list of consecutive integers from 2 up to the desired limit. Beginning with 2, mark off every second integer on the list. Move to the next unmarked number (which will be 3) and mark off every third integer. Move to the next unmarked number (which will be 5) and mark off every fifth integer. Move to the next unmarked number (which will be 7) and mark off every seventh integer. Move to the next unmarked number (which will be 11) and mark off every eleventh int Continue until the end of the list has been reached.

When completed, every unmarked entry in the list (beginning with 2) represents a prime number. Implement the Sieve of Eratosthenes with a program which performs the following tasks:

Display a friendly greeting to the user. Prompt the user for a start value > 1. We will use this later. Prompt the user for a stop value. This will be the size of the array 1. Use the stop value to create an array of type boolean and set every value to true. Execute the Sieve of Eratosthenes algorithm (using false to mark off entries) Display the total number of primes found in the interval [start, stop]. (it means the sum of primes)

What is the largest array size you can run using Java? If your program can handle arrays of larger than 2 GB, make sure you input the users integer as a long, not an int. If not, explain why.

Use your program to answer the following questions:

What is the largest sieve that your program can (in principle) complete? What is the significance of that value? How could you overcome that limitation? How long does (or would) it take your program (in seconds) to compute a sieve

up to 100,000? up to 1,000,000? up to 10,000,000? up to 100,000,000? up to 1,000,000,000? up to 1,000,000,000,000?

What is the asymptotic performance of the Sieve of Eratosthenes?

How many prime numbers exist in each of the ranges given above? Compute as many as you can, and explain why some cant be done.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students explore these related Databases questions