Lably
Skip to content

Greatest common divisor

Largest integer that divides given integers

  • 15 min read
  • 6 chapters
  • 3 labs on Lably

Learn it on Lably

In the name "greatest common divisor", the adjective "greatest" may be replaced by "highest", and the word "divisor" may be replaced by "factor", so that other names include highest common factor (HCF), etc. Historically, other names for the same concept have included greatest common measure.

This notion can be extended to polynomials (see Polynomial greatest common divisor) and other commutative rings (see § In commutative rings below).

Overview

Definition

The greatest common divisor (GCD) of integers a and b, at least one of which is nonzero, is the greatest positive integer d such that d is a divisor of both a and b; that is, there are integers e and f such that a = de and b = df, and d is the largest such integer. The GCD of a and b is generally denoted gcd(a, b).

When one of a and b is zero, the GCD is the absolute value of the nonzero integer: gcd(a, 0) = gcd(0, a) = |a|. This case is important as the terminating step of the Euclidean algorithm.

The above definition is unsuitable for defining gcd(0, 0), since there is no greatest integer n such that 0 × n = 0. However, zero is its own greatest divisor if greatest is understood in the context of the divisibility relation, so gcd(0, 0) is commonly defined as 0. This preserves the usual identities for GCD, and in particular Bézout's identity, namely that gcd(a, b) generates the same ideal as {a, b}. This convention is followed by many computer algebra systems. Nonetheless, some authors leave gcd(0, 0) undefined.

The GCD of a and b is their greatest positive common divisor in the preorder relation of divisibility. This means that the common divisors of a and b are exactly the divisors of their GCD. This is commonly proved by using either Euclid's lemma, the fundamental theorem of arithmetic, or the Euclidean algorithm. This is the meaning of "greatest" that is used for the generalizations of the concept of GCD.

Example

The number 54 can be expressed as a product of two integers in several different ways:

54×1=27×2=18×3=9×6.

Thus the complete list of divisors of 54 is 1, 2, 3, 6, 9, 18, 27, 54. Similarly, the divisors of 24 are 1, 2, 3, 4, 6, 8, 12, 24. The numbers that these two lists have in common are the common divisors of 54 and 24, that is,

1,2,3,6.

Of these, the greatest is 6, so it is the greatest common divisor:

gcd(54,24)=6.

Computing all divisors of the two numbers in this way is usually not efficient, especially for large numbers that have many divisors. Much more efficient methods are described in § Calculation.

Coprime numbers

Two numbers are called relatively prime, or coprime, if their greatest common divisor equals 1. For example, 9 and 28 are coprime.

A geometric view

For example, a 24-by-60 rectangular area can be divided into a grid of: 1-by-1 squares, 2-by-2 squares, 3-by-3 squares, 4-by-4 squares, 6-by-6 squares or 12-by-12 squares. Therefore, 12 is the greatest common divisor of 24 and 60. A 24-by-60 rectangular area can thus be divided into a grid of 12-by-12 squares, with two squares along one edge (24/12 = 2) and five squares along the other (60/12 = 5).

More generally, an a-by-b rectangle can be covered with square tiles of side length c only if c is a common divisor of a and b.

Sign in to keep reading

5 more chapters are free with a Lably account.

More in Number theory