Smallest Semi | Python3 program for the above approach ; Function to find all the prime numbers using Sieve of Eratosthenes ; Set 0 and 1 as non - prime ; If p is a prime ; Set all multiples of p as non - prime ; Function to find the smallest semi - prime number having a difference between any of its two divisors at least N ; Stores the prime numbers ; Fill the prime array ; Initialize the first divisor ; Find the value of the first prime number ; Initialize the second divisor ; Find the second prime number ; Print the semi - prime number ; Driver Code
MAX = 100001 NEW_LINE def SieveOfEratosthenes ( prime ) : NEW_LINE INDENT prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE p = 2 NEW_LINE while p * p < MAX : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * p , MAX , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT DEDENT def smallestSemiPrime ( n ) : NEW_LINE INDENT prime = [ True ] * MAX NEW_LINE SieveOfEratosthenes ( prime ) NEW_LINE num1 = n + 1 NEW_LINE while ( prime [ num1 ] != True ) : NEW_LINE INDENT num1 += 1 NEW_LINE DEDENT num2 = num1 + n NEW_LINE while ( prime [ num2 ] != True ) : NEW_LINE INDENT num2 += 1 NEW_LINE DEDENT print ( num1 * num2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 2 NEW_LINE smallestSemiPrime ( N ) NEW_LINE DEDENT