human
Smallest number greater than n that can be represented as a sum of distinct power of k | Function to find the smallest number greater than or equal to n represented as the sum of distinct powers of k.
Vector P to store the base k representation of the number.
If the representation is >= 2 , then this power of k has to be added once again and then increase the next power of k and make the current power 0.
Reduce all the lower power of k to 0.
Check if the most significant bit also satisfy the above conditions.
Converting back from the k - nary representation to decimal form ..
Driver code"
How can the above be solved in Python?

Give me a code to smallest number greater than n that can be represented as a sum of distinct power of k and the other steps required?
assistant
#Here is code to smallest number greater than n that can be represented as a sum of distinct power of k and the other steps required.
 def greaterK ( n , k ) :
	index = 0
	p = [ 0 for i in range ( n + 2 ) ]
	x = n
	while ( x > 0 ) :
		p [ index ] = x % k
		x //= k
		index += 1
	idx = 0
	for i in range ( 0 , len ( p ) - 1 , 1 ) :
		if ( p [ i ] >= 2 ) :
			p [ i ] = 0
			p [ i + 1 ] += 1
			for j in range ( idx , i , 1 ) :
				p [ j ] = 0
			idx = i + 1
		if ( p [ i ] == k ) :
			p [ i ] = 0
			p [ i + 1 ] += 1
	j = len ( p ) - 1
	if ( p [ j ] >= 2 ) :
		p [ index ] = 1
		index += 1
	ans = 0
	i = len ( p ) - 1
	while ( i >= 0 ) :
		ans = ans * k + p [ i ]
		i -= 1
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	n = 29
	k = 7
	greaterK ( n , k )