Once numbers are written as products of primes (thanks to unique factorization), their gcd and lcm can be read off directly, and a tidy identity connects the two.
Write $a$ and $b$ using the same list of primes, allowing exponent $0$: $a = \prod p^{\alpha_p}$ and $b = \prod p^{\beta_p}$. Then $$\gcd(a, b) = \prod p^{\min(\alpha_p, \beta_p)}, \qquad \operatorname{lcm}(a, b) = \prod p^{\max(\alpha_p, \beta_p)}.$$
Why it works
| $2$ | $3$ | $5$ | $7$ | |
|---|---|---|---|---|
| $a = 360$ | 3 | 2 | 1 | 0 |
| $b = 1134$ | 1 | 4 | 0 | 1 |
| gcd: smaller | 1 | 2 | 0 | 0 |
| lcm: larger | 3 | 4 | 1 | 1 |
Worked example: Reading off gcd and lcm
- Smaller exponents: $2^{1} \cdot 3^{2} \cdot 5^{0} \cdot 7^{0} = 18$.
- Larger exponents: $2^{3} \cdot 3^{4} \cdot 5 \cdot 7 = 8 \cdot 81 \cdot 35 = 22{,}680$.
- Check: $18 \cdot 22{,}680 = 408{,}240 = 360 \cdot 1134$.
Answer: $\gcd = 18$, $\operatorname{lcm} = 22{,}680$.
Worked example: Working backward
- $\gcd \cdot \operatorname{lcm} = ab$, so $b = \dfrac{12 \cdot 360}{72} = 60$.
- Check: $72 = 2^{3} \cdot 3^{2}$ and $60 = 2^{2} \cdot 3 \cdot 5$. Smaller exponents: $2^{2} \cdot 3 = 12$. Larger: $2^{3} \cdot 3^{2} \cdot 5 = 360$.
Answer: $60$.
Worked example: Three numbers
- gcd: smallest exponents, $2^{1} \cdot 3^{0} \cdot 5^{0} = 2$.
- lcm: largest exponents, $2^{2} \cdot 3^{2} \cdot 5 = 180$.
- Here $2 \cdot 180 = 360$, but $12 \cdot 18 \cdot 20 = 4320$: the product rule is only for two numbers.
Answer: $\gcd = 2$, $\operatorname{lcm} = 180$.
Common mistake
Two special cases are worth remembering. Numbers are coprime exactly when they share no prime at all; then every minimum is $0$, so $\gcd(a, b) = 1$ and $\operatorname{lcm}(a, b) = ab$. And when $a \mid b$, every exponent of $a$ is at most the matching exponent of $b$, so $\gcd(a, b) = a$ and $\operatorname{lcm}(a, b) = b$. The lcm answers "when do two cycles line up again?": lights blinking every $12$ and every $18$ seconds blink together every $\operatorname{lcm}(12, 18) = 36$ seconds.
Key idea