human
What is a code to elements of Array which can be expressed as power of some integer to given exponent K and the other steps required given the following:
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"
How can the above be solved in Python?
assistant
#Here is code to elements of Array which can be expressed as power of some integer to given exponent K and the other steps required.
 def nthRoot ( A , N ) :
	xPre = 7
	eps = 1e-3
	delX = 10 ** 9
	xK = 0
	while ( delX > eps ) :
		xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N
		delX = abs ( xK - xPre )
		xPre = xK
	return xK
def check ( no , k ) :
	kth_root = nthRoot ( no , k )
	num = int ( kth_root )
	if ( abs ( num - kth_root ) < 1e-4 ) :
		return True
	return False
def printExpo ( arr , n , k ) :
	for i in range ( n ) :
		if ( check ( arr [ i ] , k ) ) :
			print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	K = 6
	arr = [ 46656 , 64 , 256 , 729 , 16 , 1000 ]
	n = len ( arr )
	printExpo ( arr , n , K )