Problems > Least Common Multiple > Editorial

Least Common Multiple — Solution & Editorial

Back to the Problem

Divide by the gcd BEFORE multiplying so the intermediate stays in 64 bits.

Complexity: O(log)

Watch out: A·B/gcd overflows if multiplied first — 1018 is exactly the edge.