Minimize cost to make X and Y equal by given increments | Function to find gcd of x and y ; Function to find lcm of x and y ; Function to find minimum Cost ; Subtracted initial cost of x ; Subtracted initial cost of y ; Driver Code ; Returns the minimum cost required
def gcd ( x , y ) : NEW_LINE INDENT if ( y == 0 ) : NEW_LINE INDENT return x NEW_LINE DEDENT return gcd ( y , x % y ) NEW_LINE DEDENT def lcm ( x , y ) : NEW_LINE INDENT return ( x * y ) // gcd ( x , y ) NEW_LINE DEDENT def minimumCost ( x , y ) : NEW_LINE INDENT lcm_ = lcm ( x , y ) NEW_LINE costx = ( lcm_ - x ) // x NEW_LINE costy = ( lcm_ - y ) // y NEW_LINE return costx + costy NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 5 NEW_LINE y = 17 NEW_LINE print ( minimumCost ( x , y ) ) NEW_LINE DEDENT