Check whether the given numbers are Cousin prime or not | Function to check if the given Number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Returns true if n1 and n2 are Cousin primes ; Check if the given number differ by 4 or not ; Check if both numbers are prime or not ; Get the 2 numbers ; Check the numbers for cousin prime
< ? php function isPrime ( $ n ) { if ( $ n <= 1 ) return false ; if ( $ n <= 3 ) return true ; if ( $ n % 2 == 0 $ n % 3 == 0 ) return false ; for ( $ i = 5 ; $ i * $ i <= $ n ; $ i = $ i + 6 ) if ( $ n % $ i == 0 || $ n % ( $ i + 2 ) == 0 ) return false ; return true ; } function isCousinPrime ( $ n1 , $ n2 ) { if ( abs ( $ n1 - $ n2 ) != 4 ) return false ; else return ( isPrime ( $ n1 ) && isPrime ( $ n2 ) ) ; } $ n1 = 7 ; $ n2 = 11 ; if ( isCousinPrime ( $ n1 , $ n2 ) ) echo " YES " ; else echo " NO " ; ? >