Skip to content

Instantly share code, notes, and snippets.

@ashutoshkrris
Created January 31, 2021 12:57
Show Gist options
  • Select an option

  • Save ashutoshkrris/35e2fcebf31883b9246793321d46f00f to your computer and use it in GitHub Desktop.

Select an option

Save ashutoshkrris/35e2fcebf31883b9246793321d46f00f to your computer and use it in GitHub Desktop.
Prime Numbers using Sieve of Eratosthenes in Python
def seive_of_eratosthenes(n):
is_prime = [True for _ in range(n+1)]
is_prime[0], is_prime[1] = False, False
for i in range(2, int(n**0.5)+1):
for j in range(2*i, n+1, i):
is_prime[j] = False
return is_prime
if __name__ == "__main__":
n = int(input("Enter the number upto which : "))
li = seive_of_eratosthenes(n)
for i in range(n+1):
if li[i]:
print(i, end=" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment