human
Minimum number of given operation required to convert n to m | Function to return the minimum operations required.
Counting all 2 s.
Counting all 3 s.
If q contained only 2 and 3 as the only prime factors then it must be 1 now.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to minimum number of given operation required to convert n to m and the other steps required.
 def minOperations ( n , m ) :
	if ( m % n != 0 ) :
		return - 1
	minOperations = 0
	q = int ( m / n )
	while ( q % 2 == 0 ) :
		q = int ( q / 2 )
		minOperations += 1
	while ( q % 3 == 0 ) :
		q = int ( q / 3 )
		minOperations += 1
	if ( q == 1 ) :
		return minOperations
	return - 1
if __name__ == ' _ _ main _ _ ' :
	n = 120
	m = 51840
	print ( minOperations ( n , m ) )