Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Sieve of Eratosthenes (This assignment is worth 100 points) Python A prime integer is any integer greater than 1 that is evenly divisible only

The Sieve of Eratosthenes (This assignment is worth 100 points) Python

A prime integer is any integer greater than 1 that is evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It operates as follows:

Create a list with all elements initialized to 1 (true). List elements with prime indexes will remain 1. All other elements will eventually be set to zero.

Starting with list element 2, every time a list element is found whose value is 1, loop through the remainder of the list and set to zero every element whose index is a multiple of the index for the element with value 1. For list index 2, all elements beyond 2 in the list that are multiples of 2 will be set to zero (indexes 4, 6, 8, 10, etc.); for list index 3, all elements beyond 3 in the list that are multiples of 3 will be set to zero (indexes 6, 9, 12, 15, etc.); and so on.

When this process is complete, the list elements that are still set to 1 indicate that the index is a prime number. These indexes can then be printed. Write a program that uses a list of 1000 elements to determine and print the prime numbers between 2 and 999. Ignore element 0 of the list. The prime numbers must be printed out 10 numbers per line.

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

3. Is there opportunity to improve current circumstances? How so?

Answered: 1 week ago