The greatest common divisor of two integers and , not both zero, is the largest positive integer that divides both without a remainder. It is usually written . For example, , because 6 divides both numbers and no larger positive integer does. The concept is fundamental to number theory, connecting divisibility, the simplification of fractions, and the solution of equations in integers. (math.libretexts.org)
Definition and conventions
An integer divides an integer , written , if for some integer . Thus, for and not both zero, their greatest common divisor is the positive integer satisfying:
- and ;
- every common divisor of and divides .
For integers, this characterization is equivalent to being the largest positive common divisor. It also describes the relationship between the GCD and all other common divisors, rather than merely comparing their sizes. (math.libretexts.org)
Signs do not affect the result:
Since every nonzero integer divides zero,
The pair is excluded from the largest-positive-divisor definition: every positive integer divides both entries, so there is no largest one. In an extended convention, , making the GCD consistently nonnegative. (math.libretexts.org)
The definition extends to any finite nonempty collection of integers not all zero. Its GCD can be computed successively:
Thus . (aleph0.clarku.edu)
Prime factorization and basic properties
The fundamental theorem of arithmetic gives a factorization-based description. Write positive integers as products of prime numbers, using exponent zero for primes absent from a factorization:
Then
Each prime occurs in the GCD with the smaller of its two exponents. For example,
so . (uregina.ca)
Two integers whose GCD is 1 are called coprime, or relatively prime. Neither integer needs to be prime: 8 and 15 are coprime. For more than two integers, having GCD 1 is weaker than being pairwise coprime. For example, , although each pair shares a divisor greater than 1. (math.libretexts.org)
The least common multiple uses the larger prime exponent instead. Consequently, for positive integers,
The GCD is symmetric and associative, and multiplication of both inputs by a positive integer gives
These properties follow directly from the prime-exponent description. (uregina.ca)
Computing the GCD
The principal method is the Euclidean algorithm, which avoids requiring prime factorizations. Its essential step is
A number dividing and also divides ; conversely, a number dividing and divides . The two pairs therefore have exactly the same common divisors. (math.libretexts.org)
For nonnegative inputs with , choose , replace by , and repeat until the second entry is zero. The decreasing positive remainders ensure termination. The last nonzero remainder is the GCD. For example,
Hence . (math.libretexts.org)
The binary GCD algorithm instead uses subtraction, comparisons, and the removal of factors of 2. For very large integers, implementations also use methods such as Lehmer’s algorithm and subquadratic GCD algorithms. These illustrate the role of GCD computation in computer science: equivalent mathematical procedures can have different costs depending on input size and machine arithmetic. (gmplib.org)
Bézout’s identity
Bézout’s identity states that, for integers not both zero, there are integers such that
The extended Euclidean algorithm computes these coefficients alongside the GCD, or obtains them by substituting backward through the remainder equations. For the preceding example,
Thus and . (math.libretexts.org)
Every integer linear combination is divisible by the GCD. Conversely, Bézout’s identity shows that every multiple of the GCD can be expressed as such a combination. Therefore, the GCD is also the smallest positive integer expressible as . (math.libretexts.org)
Applications
Reducing fractions. If and , then
The resulting numerator and denominator are coprime, so the fraction is in lowest terms. For example, . This provides a standard representation of a rational number, with a positive denominator. (uregina.ca)
Integer equations. A linear Diophantine equation
has integer solutions exactly when , provided are not both zero. Necessity follows because the GCD divides every combination ; sufficiency follows by multiplying a Bézout identity by . (math.uwaterloo.ca)
Modular inverses. In modular arithmetic, an integer has a multiplicative inverse modulo exactly when . If , then , making an inverse. For example, , so 5 is the inverse of 3 modulo 7. (ocw.mit.edu)
Generalization to polynomials
A corresponding concept exists for polynomials. Over a field, a GCD of two nonzero polynomials divides both, and every common polynomial divisor divides it. Multiplication by a nonzero constant does not change these properties, so the result is conventionally normalized to be monic, meaning that its leading coefficient is 1. (doc.sagemath.org)
Polynomial division with remainder supplies a Euclidean algorithm in which degrees decrease instead of integer magnitudes. For example, over the rational numbers,
because the factorizations are and . Polynomial GCD computations also extend to multivariate polynomials, although they require methods beyond this simple one-variable division procedure. (doc.sagemath.org)
Historical background
Euclid treated the “greatest common measure” in Book VII of *Elements*. Proposition VII.2 gives a procedure for two numbers that are not relatively prime, while VII.3 extends the construction to three numbers. The procedure uses successive subtraction, corresponding to the remainder-based method now called the Euclidean algorithm. The terminology reflects an interpretation of one whole-number quantity as measuring another an exact number of times. (aleph0.clarku.edu)
References
- 2: Greatest common divisor and least common multiplemath.libretexts.org
- 6: The Euclidean Algorithmmath.libretexts.org
- 2: Euclidean algorithm and Bézout's algorithmmath.libretexts.org
- Miscellaneous arithmetic functions — SageMathdoc.sagemath.org
- Math 101 Course Notesuregina.ca
- Greatest Common Divisor Algorithms — GNU MPgmplib.org
- MATH 145 Algebra, Lecture Notesmath.uwaterloo.ca
- Principles of Discrete Applied Mathematics, Modular Arithmetic and Elementary Algebra Notesocw.mit.edu
- Univariate polynomials over number fields — SageMathdoc.sagemath.org
- Univariate polynomial base class — SageMathdoc.sagemath.org
- Polynomials — SageMath Constructionsdoc.sagemath.org