human
Can you provide a code to check if any permutation of N equals any power of K and the other steps required given the following:
Check if any permutation of N equals any power of K | function to check if N and K are anagrams.
Function to check if any permutation of N exist such that it is some power of K.
generate all power of K under 10 ^ 18.
check if any power of K is valid.
Driver Code.
function call to print required answer"
How can the above be solved in Python?
assistant
#Here is code to check if any permutation of N equals any power of K and the other steps required.
 def isValid ( N , K ) :
	m1 = [ ]
	m2 = [ ]
	while ( N > 0 ) :
		m1 . append ( N % 10 )
		N //= 10
	while ( K > 0 ) :
		m2 . append ( K % 10 )
		K //= 10
	if ( m1 == m2 ) :
		return True
	return False
def anyPermutation ( N , K ) :
	powK = [ 0 ] * 100
	Limit = pow ( 10 , 18 )
	powK [ 0 ] = K
	i = 1
	while ( powK [ i - 1 ] * K < Limit ) :
		powK [ i ] = powK [ i - 1 ] * K
		i += 1
	for j in range ( i ) :
		if ( isValid ( N , powK [ j ] ) ) :
			return " True "
	return " False "
if __name__ == " _ _ main _ _ " :
	N = 96889010407
	K = 7
	print ( anyPermutation ( N , K ) )