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 \mathrel \backslash m \lor p_i \mathrel \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:


 * $\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 \mathrel \backslash n \iff \forall i: 1 \le i \le r, 0 \le h_i \le l_i$

So:
 * $d \mathrel \backslash m \land d \mathrel \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\}}$