Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain line by line, what the code below is doing. It's supposed to detect prime numbers using sieve of eratosthenes alg. Output = [2

Please explain line by line, what the code below is doing. It's supposed to detect prime numbers using sieve of eratosthenes alg. Output = [2 , 3, 5, 7] # Sieve of Eratosthenes: def all_prime_below_sieve (N): # initialize a list of numbers L = [] for i in range(N): L.append(i) # 0, 1 are not prime L[0] = 0 L[1] = 0 # start sieving i = 0 while (i < N): if (L[i] != 0): p = L[i] k = i + p while (k < N): L[k] = 0 k = k + p i = i + 1 # clean the list L2 = [] for i in range(N): if (L[i] != 0): L2.append(L[i]) return L2 print(all_prime_below_sieve (10)) 

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions