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
function isPowerful ( n ) { while ( n % 2 == 0 ) { let power = 0 ; while ( n % 2 == 0 ) { n = parseInt ( n / 2 , 10 ) ; power ++ ; } if ( power == 1 ) return false ; } for ( let factor = 3 ; factor <= Math . sqrt ( n ) ; factor += 2 ) { let power = 0 ; while ( n % factor == 0 ) { n = parseInt ( n / factor , 10 ) ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } function isPower ( a ) { if ( a == 1 ) return true ; for ( let i = 2 ; i * i <= a ; i ++ ) { let val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - parseInt ( val , 10 ) ) < 0.00000001 ) return true ; } return false ; } function isAchillesNumber ( n ) { if ( isPowerful ( n ) && ! isPower ( n ) ) return true ; else return false ; } let n = 72 ; if ( isAchillesNumber ( n ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; n = 36 ; if ( isAchillesNumber ( n ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;