Consecutive Prime numbers greater than equal to given number . | python 3 program for the above approach Function to check prime . ; Function to check prime . ; It means it is not a prime ; No factor other than 1 therefore prime number ; Function to find out the required consecutive primes . ; Finding first prime just less than sqrt ( n ) . ; Finding prime just greater than sqrt ( n ) . ; Product of both prime is greater than n then print it ; Finding prime greater than second ; Driver Program
from math import sqrt NEW_LINE def is_prime ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def consecutive_primes ( n ) : NEW_LINE INDENT first = - 1 NEW_LINE second = - 1 NEW_LINE i = int ( sqrt ( n ) ) NEW_LINE while ( i >= 2 ) : NEW_LINE INDENT if ( is_prime ( i ) ) : NEW_LINE INDENT first = i NEW_LINE break NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT for i in range ( int ( sqrt ( n ) ) + 1 , n // 2 + 1 , 1 ) : NEW_LINE INDENT if ( is_prime ( i ) ) : NEW_LINE INDENT second = i NEW_LINE break NEW_LINE DEDENT DEDENT if ( first * second >= n ) : NEW_LINE INDENT print ( first , second ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( second + 1 , n + 1 , 1 ) : NEW_LINE INDENT if ( is_prime ( i ) ) : NEW_LINE INDENT print ( second , i ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 14 NEW_LINE consecutive_primes ( n ) NEW_LINE DEDENT