Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions algorithms/dynamic_programming/SieveOfEratosthenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def sieve_of_eratosthenes(n):

prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):

if (prime[p] == True):

# Update all multiples of p
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1

for p in range(2, n):
if prime[p]:
print (p),

if __name__=='__main__':
n = 30
print ("Following are the prime numbers smaller"),
print ("than or equal to", n )
sieve_of_eratosthenes(n)