Check whether given three numbers are adjacent primes | checks weather 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
< ? php function isPrime ( $ n ) { if ( $ n % 2 == 0 ) return false ; for ( $ i = 3 ; $ i * $ i <= $ n ; $ i += 2 ) if ( $ n % $ i == 0 ) return false ; return true ; } function nextPrime ( $ start ) { $ next = $ start + 1 ; while ( ! isPrime ( $ next ) ) $ next ++ ; return $ next ; } function areAdjacentPrimes ( $ a , $ b , $ c ) { if ( ! isPrime ( $ a ) || ! isPrime ( $ b ) || ! isPrime ( $ c ) ) return false ; $ next = nextPrime ( $ a ) ; if ( $ next != $ b ) return false ; if ( nextPrime ( $ b ) != $ c ) return false ; return true ; } if ( areAdjacentPrimes ( 11 , 13 , 19 ) ) echo " Yes " ; else echo " No " ; ? >