Topics

Formulalcm(a, b) = a / gcd(a, b) * b (prevents overflow).
GCD can be computed using euclid’s algorithm or built-in __gcd (C++)

int lcm(int a, int b) {
    return (a / gcd(a, b)) * b; // Order matters to avoid overflow
}