MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / SOE

Function SOE

other/findingPrimes.py:9–21  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

7
8from math import sqrt
9def SOE(n):
10 check = round(sqrt(n)) #Need not check for multiples past the square root of n
11
12 sieve = [False if i <2 else True for i in range(n+1)] #Set every index to False except for index 0 and 1
13
14 for i in range(2, check):
15 if(sieve[i] == True): #If i is a prime
16 for j in range(i+i, n+1, i): #Step through the list in increments of i(the multiples of the prime)
17 sieve[j] = False #Sets every multiple of i to False
18
19 for i in range(n+1):
20 if(sieve[i] == True):
21 print(i, end=" ")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected