Check if a number is an Achilles number or not | Function to check if the number is powerful number ; First divide the number repeatedly by 2 ; If only 2 ^ 1 divides n ( not higher powers ) , then return false ; if n is not a power of 2 then this loop will execute repeat above process ; Find highest power of " factor " that divides n ; If only factor ^ 1 divides n ( not higher powers ) , then return false ; n must be 1 now if it is not a prime number . Since prime numbers are not powerful , we return false if n is not 1. ; Utility function to check if number is a perfect power or not ; Function to check Achilles Number ; Driver Code
< ? php function isPowerful ( $ n ) { while ( $ n % 2 == 0 ) { $ power = 0 ; while ( $ n % 2 == 0 ) { $ n /= 2 ; $ power ++ ; } if ( $ power == 1 ) return false ; } for ( $ factor = 3 ; $ factor <= sqrt ( $ n ) ; $ factor += 2 ) { $ power = 0 ; while ( $ n % $ factor == 0 ) { $ n = $ n / $ factor ; $ power ++ ; } if ( $ power == 1 ) return false ; } return ( $ n == 1 ) ; } function isPower ( $ a ) { if ( $ a == 1 ) return true ; for ( $ i = 2 ; $ i * $ i <= $ a ; $ i ++ ) { $ val = log ( $ a ) / log ( $ i ) ; if ( ( $ val - ( int ) $ val ) < 0.00000001 ) return true ; } return false ; } function isAchillesNumber ( $ n ) { if ( isPowerful ( $ n ) && ! isPower ( $ n ) ) return true ; else return false ; } $ n = 72 ; if ( isAchillesNumber ( $ n ) ) echo " YES " , " STRNEWLINE " ; else echo " NO " , " STRNEWLINE " ; $ n = 36 ; if ( isAchillesNumber ( $ n ) ) echo " YES " , " STRNEWLINE " ; else echo " NO " , " STRNEWLINE " ; ? >