Perfect power ( 1 , 4 , 8 , 9 , 16 , 25 , 27 , ... ) | Function that keeps all the odd power numbers upto n ; We need exclude perfect squares . ; Return sum of odd and even powers . ; Driver Code
function powerNumbers ( n ) { let v = new Set ( ) ; for ( let i = 2 ; i * i * i <= n ; i ++ ) { let j = i * i ; while ( j * i <= n ) { j *= i ; let s = parseInt ( Math . sqrt ( j ) , 10 ) ; if ( s * s != j ) v . add ( j ) ; } } return v . size + parseInt ( Math . sqrt ( n ) , 10 ) ; } document . write ( powerNumbers ( 50 ) ) ;