LCM
The LCM (least common multiple) is the smallest positive integer that is a multiple of two or more integers, computed via the GCD.
Purpose
To find the least common multiple of integers, used in period alignment and fraction arithmetic.
Mechanism
lcm(a,b) = |a×b| / gcd(a,b). The LCM of several numbers is computed recursively: lcm(a,b,c) = lcm(lcm(a,b),c). Since a×b may overflow, divide before multiplying: lcm = a / gcd(a,b) × b.
Use cases
- Periodic event alignment (scheduled tasks)
- Common denominators for fraction arithmetic
- Gear teeth calculation
- Signal synchronization
Examples
- Input
lcm(4, 6)Output12The least common multiple of 4 and 6
Common errors
- Multiplying a×b before dividing overflows
- Divide a/gcd first, then multiply by b
Related terms
GCD
The GCD (greatest common divisor) is the largest positive integer that divides two or more integers, computed efficiently with the Euclidean algorithm. GLOSSARY
Prime Number
A prime number is a natural number greater than 1 divisible only by 1 and itself; it is the building block of number theory, and every integer factors uniquely into primes. GLOSSARY