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 INT_MAX ; x ^ K denotes current value of x ; loop untiwe 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
def nthRoot ( A , N ) : NEW_LINE INDENT xPre = 7 NEW_LINE eps = 1e-3 NEW_LINE delX = 10 ** 9 NEW_LINE xK = 0 NEW_LINE while ( delX > eps ) : NEW_LINE INDENT xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N NEW_LINE delX = abs ( xK - xPre ) NEW_LINE xPre = xK NEW_LINE DEDENT return xK NEW_LINE DEDENT def check ( no , k ) : NEW_LINE INDENT kth_root = nthRoot ( no , k ) NEW_LINE num = int ( kth_root ) NEW_LINE if ( abs ( num - kth_root ) < 1e-4 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def printExpo ( arr , n , k ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( check ( arr [ i ] , k ) ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 6 NEW_LINE arr = [ 46656 , 64 , 256 , 729 , 16 , 1000 ] NEW_LINE n = len ( arr ) NEW_LINE printExpo ( arr , n , K ) NEW_LINE DEDENT