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
def isMakeZero ( arr , N , K ) : NEW_LINE INDENT MP = { } NEW_LINE V = [ ] NEW_LINE X = 1 NEW_LINE while ( X > 0 and X < 10 ** 20 ) : NEW_LINE INDENT V . append ( X ) NEW_LINE X *= K NEW_LINE DEDENT for i in range ( 0 , N , 1 ) : NEW_LINE INDENT for j in range ( len ( V ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( V [ j ] not in MP and V [ j ] <= arr [ i ] ) : NEW_LINE INDENT arr [ i ] -= V [ j ] NEW_LINE MP [ V [ j ] ] = 1 NEW_LINE DEDENT DEDENT if ( arr [ i ] != 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( i < N - 1 ) : NEW_LINE INDENT return " No " NEW_LINE DEDENT else : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT DEDENT arr = [ 8 , 0 , 3 , 4 , 80 ] NEW_LINE N = len ( arr ) NEW_LINE K = 2 NEW_LINE print ( isMakeZero ( arr , N , K ) ) NEW_LINE