Elements of Array which can be expressed as power of some integer to given exponent K | Method returns Nth power of A ; Smaller eps , denotes more accuracy ; Initializing difference between two roots by Integer . MAX_VALUE ; x ^ K denotes current value of x ; loop untill we reach desired accuracy ; calculating current value from previous value by newton 's method ; Function to check whether its k root is an integer or not ; Function to find the numbers ; Driver code
function nthRoot ( A , N ) { let xPre = 7 ; let eps = 1e-3 ; let delX = Number . MAX_VALUE ; let xK = 0 ; while ( delX > eps ) { xK = ( ( N - 1.0 ) * xPre + A / Math . pow ( xPre , N - 1 ) ) / N ; delX = Math . abs ( xK - xPre ) ; xPre = xK ; } return xK ; } function check ( no , k ) { let kth_root = nthRoot ( no , k ) ; let num = Math . floor ( kth_root ) ; if ( Math . abs ( num - kth_root ) < 1e-4 ) return true ; return false ; } function printExpo ( arr , n , k ) { for ( let i = 0 ; i < n ; i ++ ) { if ( check ( arr [ i ] , k ) ) document . write ( arr [ i ] + " " ) ; } } let K = 6 ; let arr = [ 46656 , 64 , 256 , 729 , 16 , 1000 ] ; let n = arr . length ; printExpo ( arr , n , K ) ;