Check if a number is an Unusual Number or not | Utility function to find largest prime factor of a number ; Initialize the maximum prime factor variable with the lowest one ; Print the number of 2 s that divide n ; $n >>= 1 ; equivalent to n /= 2 ; n must be odd at this point , thus skip the even numbers and iterate only for odd integers ; This condition is to handle the case when n is a prime number greater than 2 ; Function to check Unusual number ; Get the largest Prime Factor of the number ; Check if largest prime factor is greater than sqrt ( n ) ; Driver Code
< ? php function largestPrimeFactor ( $ n ) { $ max = -1 ; while ( $ n % 2 == 0 ) { $ max = 2 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i += 2 ) { while ( $ n % $ i == 0 ) { $ max = $ i ; $ n = $ n / $ i ; } } if ( $ n > 2 ) $ max = $ n ; return $ max ; } function checkUnusual ( $ n ) { $ factor = largestPrimeFactor ( $ n ) ; if ( $ factor > sqrt ( $ n ) ) { return true ; } else { return false ; } } $ n = 14 ; if ( checkUnusual ( $ n ) ) { echo " YES " . " STRNEWLINE " ; } else { echo " NO " . " STRNEWLINE " ; } ? >