Finding Common Structure
The greatest common divisor is the largest positive integer dividing both and . For , since 6 divides both and nothing larger does. Its partner, the least common multiple , is the smallest positive integer that both and divide. These govern fraction arithmetic, tiling problems, and modular equations.
You could compute the gcd from prime factorizations (take the lower power of each shared prime), but the Euclidean algorithm is far faster and needs no factoring. It rests on a single fact: where is the remainder of divided by . Repeatedly replace the pair by (divisor, remainder) until the remainder is 0; the last nonzero remainder is the gcd. For : This terminates quickly because the remainders shrink rapidly — it is one of the oldest and most elegant algorithms known.
Two numbers are coprime (relatively prime) when — they share no prime factor. Coprimality is central to modular arithmetic (a number has a multiplicative inverse mod exactly when it is coprime to ).
A beautiful identity links gcd and lcm: . So once you have the gcd (fast via Euclid), the lcm is just — you never need to factor to find either.
Common pitfall: confusing the gcd (greatest common divisor, a factor of both) with the lcm (least common multiple, a multiple of both). The gcd is at most the smaller number; the lcm is at least the larger. For 12 and 18, gcd = 6 (small) and lcm = 36 (large) — mixing them up inverts the relationship. Remember .