LCM on a collection of numbers is: commutative, associative and idempotent Therefore: LCM(a, b) = a * b / gcd(a.b) LCM(a,b,c) = LCM(a,b) * c / gcd(LCM(a,b), ans)