Print all Prime numbers Using Sieve of Eratosthenes
from math import sqrt
def allPrime(n):
l=[True]*(n+1)
l[0]=False
l[1]=False
for i in range(2,int(sqrt(n))+1):
if l[i]==True:
for j in range(i*i,n+1,i):
l[j]=False
for i in range(n+1):
if l[i]==True:
print(i,end=" ")
n=int(input())
allPrime(n)
Comments
Post a Comment