# Greatest Common Divisor

The **greatest common divisor (GCD)** of a set of integers is the largest integer that divides each integer in the set.

Find the greatest common divisor of \( 30, 36, 28.\)

The divisors of each number are given by

\[ \begin{align} 30: &1, 2, 3, 5, 6, 10, 15, 30 \\ 36: &1, 2, 3, 4, 6, 9, 12, 18, 36 \\ 28: &1, 2, 4, 7, 14, 28 \end{align} \]

The largest number that appears on every list is \( 2,\) so this is the greatest common divisor:

\[ \gcd(30,36,28)=2.\ _\square\]

The GCD is a fundamental concept in number theory, and is taught to elementary school students as an aid to reducing fractions: dividing the top and bottom of a fraction \(\frac{a}{b}\) by the GCD of \(a,b\) will put it in lowest terms.

What is \( \frac{246}{642}\) in lowest terms?

By listing divisors as above (or via other methods--see below), it can be shown that the greatest common divisor of \(246\) and \(642\) is \(6.\) Divide the top and bottom by \( 6\) to get \(\color\red \frac{41}{107}\). This fraction is in lowest terms, because the only positive integer that divides both \( 41\) and \( 107\) is \(1.\)

The GCDs in this example are written \( \gcd(246,642)=6\) and \(\gcd(41,107)=1.\) \(_\square\)

Pairs of integers, such as \(41\) and \(107,\) whose gcd is \( 1\) are called relatively prime.

The GCD is important for multiplication in modular arithmetic, and is essential in applications of elementary number theory, including RSA encryption and algorithms for factoring large integers.

## Computing the GCD

The example in the introduction was computed by listing the positive divisors of each number and searching for the largest number that appeared in every list. This is a very ineffective way to compute the GCD in general.

If the prime factorization of the numbers in the list is known, then computing the greatest common divisor is much simpler. The primes in the factorization of the GCD are the primes that appear in the factorizations of every number in the list, and their exponent in the GCD is the minimum of the exponents that appear in the factorizations in the list.

Compute \( \gcd(4200,3780,3528)\) using prime factorizations.

We have

\[\begin{align} 4200 &= 2^3 \cdot 3^{\phantom 1} \cdot 5^2 \cdot 7 \\ 3780 &= 2^2 \cdot 3^3 \cdot 5^{\phantom 1} \cdot 7 \\ 3528 &= 2^3 \cdot 3^2 \ \ \phantom{\cdot 5^0} \cdot 7^2. \end{align}\]

The GCD can be read off from these factorizations by using the smallest power of each prime that appears everywhere. This is

\[ 2^2 \cdot 3 \cdot 7 = 84.\ _\square\]

Generalizing this example, if the prime factorizations of \(a\) and \(b\) are

\[a = p_1 ^{\alpha_1} p_2 ^{\alpha_2} \ldots p_k ^{\alpha_k}, \quad b = p_1 ^{\beta_1} p_2 ^ {\beta_2} \ldots p_k ^ {\beta_k},\]

where the \(p_i\) are distinct primes and the \(\alpha_i\) and \( \beta_i\) are nonnegative integers, then

\[ \gcd(a,b) = p_1 ^{\min(\alpha_1, \beta_1)} p_2 ^{\min(\alpha_2, \beta_2)} \ldots p_k ^{\min(\alpha_k, \beta_k)} . \]

A similar formula holds for finding the GCD of several integers, by taking the smallest exponent for each prime.

## Properties of the GCD

The GCD has many important properties which follow from divisibility rules and properties of the integers.

The GCD of a list of numbers is

*divisible by*any other common divisor.

This is clear from the description using prime factorizations.Bezout's identity: \( \gcd(a,b)\) is the smallest positive integer that can be written in the form \(ax+by\) for some integers \(x\) and \(y.\)

This is an important identity for computing multiplicative inverses in modular arithmetic (and, more generally, for exploring the ideals of the positive integers and other rings).The GCD of a list of numbers can be computed two at a time; e.g. \( \gcd(a,b,c) = \gcd(\gcd(a,b),c).\)

So algorithms for computing the GCD can concentrate on the GCD of two numbers, since the GCD of a larger list can be reduced to the computation of the GCDs of several pairs of numbers.\( \gcd(a,b) = \gcd(a-bq,b)\) for any integer \(q.\)

This fact is used repeatedly in the Euclidean algorithm (see below) to simplify the computation of the GCD.If \(a|bc\) and \( \gcd(a,b) =1,\) then \( a|c.\)

This is an important fact related to unique factorization. It follows from Bezout's identity: write \(ax+by=1,\) so \( acx+bcy=c,\) and \(a\) divides both terms on the left side, so it must divide the right side.

## Euclidean Algorithm

For large numbers, it is often difficult and time-consuming to compute prime factorizations. There is a very efficient method called the Euclidean algorithm which computes the GCD of two integers without requiring their prime factorizations. The key fact that it uses is the identity \( \gcd(a,b) = \gcd(a-bq,b)\) for any integer \(q.\) This allows for the numbers \(a,b\) to be reduced recursively by successive divisions without changing the GCD. See the wiki for details.

## Problem Solving

How many ordered pairs of integers \( (a,b) \) are there, such that \( 100 \leq a \leq 1000, 100 \leq b \leq 1000 \) and

\[ \frac{a}{b} = \frac{12}{21}? \]

**Details and Assumptions:**

- For an
**ordered pair of integers**\((a,b)\), the order of the integers matter. The ordered pair \((1, 2)\) is different from the ordered pair \((2,1) \).

**Cite as:**Greatest Common Divisor.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/greatest-common-divisor/