Minimum operations required to make two numbers equal | Function to return the minimum operations required ; Keeping B always greater ; Reduce B such that gcd ( A , B ) becomes 1. ; Driver code
function minOperations ( A , B ) { if ( A > B ) { A = A + B ; B = A - B ; A = A - B ; } B = B / __gcd ( A , B ) ; return B - 1 ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var A = 7 , B = 15 ; document . write ( minOperations ( A , B ) + " " ) ;