Segmented Sieve | This functions finds all primes smaller than ' limit ' using simple sieve of eratosthenes . ; Create a boolean array " mark [ 0 . . limit - 1 ] " and initialize all entries of it as true . A value in mark [ p ] will finally be false if ' p ' is Not a prime , else true . ; One by one traverse all numbers so that their multiples can be marked as composite . ; If p is not changed , then it is a prime ; Update all multiples of p ; Print all prime numbers and store them in prime
def simpleSieve ( limit ) : NEW_LINE INDENT mark = [ True for i in range ( limit ) ] NEW_LINE for p in range ( p * p , limit - 1 , 1 ) : NEW_LINE INDENT if ( mark [ p ] == True ) : NEW_LINE INDENT for i in range ( p * p , limit - 1 , p ) : NEW_LINE INDENT mark [ i ] = False NEW_LINE DEDENT DEDENT DEDENT for p in range ( 2 , limit - 1 , 1 ) : NEW_LINE INDENT if ( mark [ p ] == True ) : NEW_LINE INDENT print ( p , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT