human
Minimize divisions by 2 , 3 , or 5 required to make two given integers equal | Function to calculate GCD of two numbers.
Base Case.
Calculate GCD recursively.
Function to count the minimum number of divisions required to make X and Y equal.
Calculate GCD of X and Y.
Divide X and Y by their GCD.
Stores the number of divisions.
Iterate until X != Y.
Maintain the order X <= Y.
If X is divisible by 2 , then divide X by 2.
If X is divisible by 3 , then divide X by 3.
If X is divisible by 5 , then divide X by 5.
If X is not divisible by 2 , 3 , or 5 , then pr - 1.
Increment count by 1.
Print the value of count as the minimum number of operations.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimize divisions by 2 , 3 , or 5 required to make two given integers equal and the other steps required.
 def gcd ( a , b ) :
	if ( b == 0 ) :
		return a
	return gcd ( b , a % b )
def minimumOperations ( X , Y ) :
	GCD = gcd ( X , Y )
	X = X // GCD
	Y = Y // GCD
	count = 0
	while ( X != Y ) :
		if ( Y > X ) :
			X , Y = Y , X
		if ( X % 2 == 0 ) :
			X = X // 2
		elif ( X % 3 == 0 ) :
			X = X // 3
		elif ( X % 5 == 0 ) :
			X = X // 5
		else :
			print ( " - 1" )
			return
		count += 1
	print ( count )
if __name__ == ' _ _ main _ _ ' :
	X , Y = 15 , 20
	minimumOperations ( X , Y )