GCD from Prime Decomposition

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

From Expression for Integers as Powers of Same Primes, 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 \divides m \lor p_i \divides 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 \set {m, n} = p_1^{\min \set {k_1, l_1} } p_2^{\min \set {k_2, l_2} } \ldots p_r^{\min \set {k_r, l_r} }$

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

Proof
Let $d \divides m$.

Then:


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

So:
 * $d \divides m \land d \divides n \iff \forall i: 1 \le i \le r, 0 \le h_i \le \min \set {k_i, l_i}$

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

So for each $i \in \closedint 1 r$, $h_i$ needs to equal $\min \set {k_i, l_i}$.

Hence the result:


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