Check whether given three numbers are adjacent primes | Function checks whether given number is prime or not . ; Check if n is a multiple of 2 ; If not , then just check the odds ; Return next prime number ; Start with next number ; Breaks after finding next prime number ; Check given three numbers are adjacent primes are not ; Check given three numbers are primes are not ; Find next prime of a ; If next is not same as 'a ; If next next is not same as 'c ; Driver code for above functions
def isPrime ( n ) : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = 3 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = i + 2 NEW_LINE DEDENT return True NEW_LINE DEDENT def nextPrime ( start ) : NEW_LINE INDENT nxt = start + 1 NEW_LINE while ( isPrime ( nxt ) == False ) : NEW_LINE INDENT nxt = nxt + 1 NEW_LINE DEDENT return nxt NEW_LINE DEDENT def areAdjacentPrimes ( a , b , c ) : NEW_LINE INDENT if ( isPrime ( a ) == False or isPrime ( b ) == False or isPrime ( c ) == False ) : NEW_LINE INDENT return False NEW_LINE DEDENT nxt = nextPrime ( a ) NEW_LINE DEDENT ' NEW_LINE INDENT if ( nxt != b ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT if ( nextPrime ( b ) != c ) : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT if ( areAdjacentPrimes ( 11 , 13 , 19 ) ) : NEW_LINE INDENT print ( " Yes " ) , NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT