human
Write me a code to smallest number greater than or equal to N having sum of digits not exceeding S and the other steps required given the following:
Smallest number greater than or equal to N having sum of digits not exceeding S | Function to calculate sum of digits of n.
Function to find the smallest possible integer satisfying the given condition.
If sum of digits is already smaller than s.
Initialize variables.
Find the k - th digit.
Add remaining.
If sum of digits does not exceed s.
Update K.
Given N and S.
Function call"
Solution in Python:
assistant
#Here is code to smallest number greater than or equal to N having sum of digits not exceeding S and the other steps required.
 def sum ( n ) :
	sm = 0
	while ( n > 0 ) :
		sm += n % 10
		n //= 10
	return sm
def smallestNumber ( n , s ) :
	if ( sum ( n ) <= s ) :
		return n
	ans , k = n , 1
	for i in range ( 9 ) :
		digit = ( ans // k ) % 10
		add = k * ( ( 10 - digit ) % 10 )
		ans += add
		if ( sum ( ans ) <= s ) :
			break
		k *= 10
	return ans
n , s = 3 , 2
print ( smallestNumber ( n , s ) )