human
What is a code to form N by adding 1 or 2 in minimum number of operations X where X is divisible by M and the other steps required given the following:
Form N by adding 1 or 2 in minimum number of operations X where X is divisible by M | Function to calculate the minimum number of steps required total steps taken is divisible by m and only 1 or 2 steps can be taken at a time.
If m > n ans is - 1.
else discussed above approach.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to form N by adding 1 or 2 in minimum number of operations X where X is divisible by M and the other steps required.
 def minsteps ( n , m ) :
	if ( m > n ) :
		return - 1
	else :
		return ( ( n + 1 ) // 2 + m - 1 ) // m * m ;
n = 17
m = 4
ans = minsteps ( n , m )
print ( ans )