text: Check if N is Strong Prime | Utility function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function that returns true if n is a strong prime ; If n is not a prime number or n is the first prime then return false ; Initialize previous_prime to n - 1 and next_prime to n + 1 ; Find next prime number ; Find previous prime number ; Arithmetic mean ; If n is a strong prime ; Driver code
code: < ? 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 isStrongPrime ( $ n ) { if ( ! isPrime ( $ n ) $ n == 2 ) return false ; $ previous_prime = $ n - 1 ; $ next_prime = $ n + 1 ; while ( ! isPrime ( $ next_prime ) ) $ next_prime ++ ; while ( ! isPrime ( $ previous_prime ) ) $ previous_prime -- ; $ mean = ( $ previous_prime + $ next_prime ) / 2 ; if ( $ n > $ mean ) return true ; else return false ; } $ n = 11 ; if ( isStrongPrime ( $ n ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >