Smallest composite number not divisible by first N prime numbers | Initializing the max value ; Function to generate N prime numbers using Sieve of Eratosthenes ; Stores the primes ; Setting all numbers to be prime initially ; If a prime number is encountered ; Set all its multiples as composites ; Store all the prime numbers ; Function to find the square of the ( N + 1 ) - th prime number ; Driver Code ; Stores all prime numbers
MAX_SIZE = 1000005 NEW_LINE def SieveOfEratosthenes ( StorePrimes ) : NEW_LINE INDENT IsPrime = [ True for i in range ( MAX_SIZE ) ] NEW_LINE p = 2 NEW_LINE while ( p * p < MAX_SIZE ) : NEW_LINE INDENT if ( IsPrime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * p , MAX_SIZE , p ) : NEW_LINE INDENT IsPrime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT for p in range ( 2 , MAX_SIZE ) : NEW_LINE INDENT if ( IsPrime [ p ] ) : NEW_LINE INDENT StorePrimes . append ( p ) NEW_LINE DEDENT DEDENT DEDENT def Smallest_non_Prime ( StorePrimes , N ) : NEW_LINE INDENT x = StorePrimes [ N ] NEW_LINE return x * x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE StorePrimes = [ ] NEW_LINE SieveOfEratosthenes ( StorePrimes ) NEW_LINE print ( Smallest_non_Prime ( StorePrimes , N ) ) NEW_LINE DEDENT