set low to 1 and high to max ( a , b ) * n , here we have taken high as 10 ^ 18
low = 1 ; high = sys . maxsize NEW_LINE lcm = ( a * b ) // gcd ( a , b ) NEW_LINE while low < high : NEW_LINE INDENT mid = low + ( high - low ) // 2 NEW_LINE DEDENT