Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program and Flowchart 2) Write a program to generate a list of the prime numbers less than 50000 using the Sieve of Eratosthenes. The algorithm

Program and Flowchart image text in transcribed
2) Write a program to generate a list of the prime numbers less than 50000 using the Sieve of Eratosthenes. The algorithm is explained in the following extract from Wikipedia. Example To find all the prime numbers less than or equal to 30 proceed as follows. First, generate a list of integers from 2 to 30: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The first number in the list is 2: cross out every 2nd number in the list after 2 by counting up from 2 in increments of 2 (these will be all the multiples of 2 in the list): 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The next number in the list after 2 is 3; cross out every 3rd number in the list after 3 by counting up from 3 in increments of 3 (these will be all the multiples of 3 in the list): 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The next number not yet crossed out in the list after 3 is 5; cross out every 5th number in the list after 5 by counting up from 5 in increments of 5 (i.c. all the multiples of 5): 2 3 4 5 6-7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The next number not yet crossed out in the list after 5 is 7; the next step would be to cross out every 7th number in the list after 7, but they are all already crossed out at this point, as these numbers (14, 21, 28) are also multiples of smaller primes because 7 x 7 is greater than 30. The numbers not crossed out at this point in the list are all the prime numbers below 30: 11 13 17 19 23 2 3 3 You should first write a flowchart for the algorithm and then code it on paper, before trying to write the Python program. You may find the try/except construct is useful here https://www.w3schools.com/python/python try except.asp When you have the list of primes, check your result by summing it. The answer is 121013308

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

Step: 3

blur-text-image

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

Students also viewed these Databases questions