GCD from Prime Decomposition

Theorem
Let $a, b \in \Z$.

From Expression for Integers as Powers of Same Primes, let:

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

Then:
 * $\gcd \set {a, b} = 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 {a, b}$ denotes the greatest common divisor of $a$ and $b$.

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

Let $d \divides a$.

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

So:
 * $d \divides a \land d \divides b \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 {a, b} = 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} }$

Also see

 * LCM from Prime Decomposition