Skip to content
uencoder

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)
    Output
    12

    The 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

Related tools

References