Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Sieve of Eratosthenes added #324

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions Python/SieveOfEratosthenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python program to print all primes smaller than or equal to
# n using Sieve of Eratosthenes

def SieveOfEratosthenes(n):

# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):

# If prime[p] is not changed, then it is a prime
if (prime[p] == True):

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

# driver program
if __name__=='__main__':
n = 30
print "Following are the prime numbers smaller",
print "than or equal to", n
SieveOfEratosthenes(n)
2 changes: 1 addition & 1 deletion Python/palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def isPalindrome(s):
print("Yes, It's a PALINDROME")

else:
`print("Not PALINDROME")
print("Not PALINDROME")