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

Popular posts from this blog

Trouble with the Number System

Residue Arithmetic

Perfect Peak of Array