GCD 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 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 decompositions of either one of $m$ or $n$, then its corresponding index $k_i$ or $l_i$ will be zero.

Then:


 * $\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\}}$

where $\gcd \left\{{m, n}\right\}$ denotes the greatest common divisor of $m$ and $n$.

Proof
Let $d \mathop \backslash m$. Now:


 * $d$ is of the form $p_1^{h_1} p_2^{h_2} \ldots p_r^{h_r}, \forall i: 1 \le i \le r, 0 \le h_i \le k_i$.
 * $d \mathop \backslash n \iff \forall i: 1 \le i \le r, 0 \le h_i \le l_i$

So $d \mathop \backslash m \land d \mathop \backslash n \iff \forall i: 1 \le i \le r, 0 \le h_i \le \min \left\{{k_i, l_i}\right\}$.

For $d$ to be at its greatest, we want the largest possible exponent for each of these primes.

So for each $i \in \left[{1 \,.\,.\, r}\right]$, $h_i$ needs to equal $\min \left\{{k_i, l_i}\right\}$.

Hence the result:

$\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\}}$