Math Fundamentals18 sections · 814 units
Open in Course

LCM of Arrays

Folding and overflow

To find LCM of an array, fold left: result = a1, then result = lcm(result, a2), and so on.

Warning: LCM grows fast. lcm(2, 3, 5, 7, 11, 13) = 30030. If array is large, LCM can exceed even 64-bit integers.

Use modular arithmetic if problem asks for answer mod some prime. Otherwise check for overflow after each step.