GCD and LCM from Prime Decomposition

Theorem
Let $m, n \in \Z$.

Let:
 * $m = p_1^{k_1} p_2^{k_2} \ldots p_r^{k_r}$
 * $n = p_1^{l_1} p_2^{l_2} \ldots p_r^{l_r}$
 * $p_i \mathop \backslash m \lor p_i \mathop \backslash n, 1 \le i \le r$.

That is, the primes given in these prime decompositions may be divisors of either of the numbers $m$ or $n$.

Note that if one of the primes $p_i$ does not appear in the prime decompositions of either one of $m$ or $n$, then its corresponding index $k_i$ or $l_i$ will be zero.

Then the following results apply:


 * $\gcd \left\{{m, n}\right\} = p_1^{\min \left\{{k_1, l_1}\right\}} p_2^{\min \left\{{k_2, l_2}\right\}} \ldots p_r^{\min \left\{{k_r, l_r}\right\}}$


 * $\operatorname{lcm} \left\{{m, n}\right\} = p_1^{\max \left\{{k_1, l_1}\right\}} p_2^{\max \left\{{k_2, l_2}\right\}} \ldots p_r^{\max \left\{{k_r, l_r}\right\}}$

Proof
The proof of these results can be found in:


 * GCD from Prime Decomposition
 * LCM from Prime Decomposition