human
Can you provide a code to modify array by making all array elements equal to 0 by subtracting K ^ i from an array element in every i and the other steps required given the following:
Modify array by making all array elements equal to 0 by subtracting K ^ i from an array element in every i | Function to check whether all array elements can be made zero or not.
Stores if a power of K has already been subtracted or not.
Stores all the Kth power.
Iterate until X is less than INT_MAX.
Traverse the array arr [ ].
Iterate over the range [ 0 , M ].
If MP [ V [ j ] ] is 0 and V [ j ] is less than or equal to arr [ i ].
If arr [ i ] is not 0.
If i is less than N - 1.
Otherwise ,.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to modify array by making all array elements equal to 0 by subtracting K ^ i from an array element in every i and the other steps required.
 def isMakeZero ( arr , N , K ) :
	MP = { }
	V = [ ]
	X = 1
	while ( X > 0 and X < 10 ** 20 ) :
		V . append ( X )
		X *= K
	for i in range ( 0 , N , 1 ) :
		for j in range ( len ( V ) - 1 , - 1 , - 1 ) :
			if ( V [ j ] not in MP and V [ j ] <= arr [ i ] ) :
				arr [ i ] -= V [ j ]
				MP [ V [ j ] ] = 1
		if ( arr [ i ] != 0 ) :
			break
	if ( i < N - 1 ) :
		return " No "
	else :
		return " Yes "
arr = [ 8 , 0 , 3 , 4 , 80 ]
N = len ( arr )
K = 2
print ( isMakeZero ( arr , N , K ) )