{
  "id": "greatest-common-divisor",
  "title": "Greatest Common Divisor",
  "lang": "en",
  "source_lang": "en",
  "summary": "The greatest common divisor is the largest positive integer that divides each of a given collection of integers without a remainder.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "GCD",
    "gcd",
    "Greatest common factor",
    "GCF",
    "Highest common factor",
    "HCF",
    "Greatest common measure"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/greatest-common-divisor/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/greatest-common-divisor/",
      "json": "https://aiwiki.page/zh/greatest-common-divisor.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The greatest common divisor of two integers \\(a\\) and \\(b\\), not both zero, is the largest positive integer that divides both without a remainder. It is usually written \\(\\gcd(a,b)\\). For example, \\(\\gcd(18,24)=6\\), 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)"
    },
    {
      "heading": "Definition and conventions",
      "text": "An integer \\(c\\) divides an integer \\(a\\), written \\(c\\mid a\\), if \\(a=ck\\) for some integer \\(k\\). Thus, for \\(a\\) and \\(b\\) not both zero, their greatest common divisor is the positive integer \\(d\\) satisfying:\n\n- \\(d\\mid a\\) and \\(d\\mid b\\);\n- every common divisor of \\(a\\) and \\(b\\) divides \\(d\\).\n\nFor 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)\n\nSigns do not affect the result:\n\n\\[\\gcd(a,b)=\\gcd(|a|,|b|).\\]\n\nSince every nonzero integer divides zero,\n\n\\[\\gcd(a,0)=|a|\\qquad(a\\ne0).\\]\n\nThe pair \\((0,0)\\) is excluded from the largest-positive-divisor definition: every positive integer divides both entries, so there is no largest one. In an extended convention, \\(\\gcd(0,0)=0\\), making the GCD consistently nonnegative. (math.libretexts.org)\n\nThe definition extends to any finite nonempty collection of integers not all zero. Its GCD can be computed successively:\n\n\\[\\gcd(a,b,c)=\\gcd(\\gcd(a,b),c).\\]\n\nThus \\(\\gcd(12,18,30)=6\\). (aleph0.clarku.edu)"
    },
    {
      "heading": "Prime factorization and basic properties",
      "text": "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:\n\n\\[a=\\prod_p p^{\\alpha_p}, \\qquad b=\\prod_p p^{\\beta_p}.\\]\n\nThen\n\n\\[\\gcd(a,b)=\\prod_p p^{\\min(\\alpha_p,\\beta_p)}.\\]\n\nEach prime occurs in the GCD with the smaller of its two exponents. For example,\n\n\\[72=2^3 3^2,\\qquad 120=2^3 3\\,5,\\]\n\nso \\(\\gcd(72,120)=2^3 3=24\\). (uregina.ca)\n\nTwo 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, \\(\\gcd(6,10,15)=1\\), although each pair shares a divisor greater than 1. (math.libretexts.org)\n\nThe least common multiple uses the larger prime exponent instead. Consequently, for positive integers,\n\n\\[\\gcd(a,b)\\operatorname{lcm}(a,b)=ab.\\]\n\nThe GCD is symmetric and associative, and multiplication of both inputs by a positive integer \\(k\\) gives\n\n\\[\\gcd(ka,kb)=k\\gcd(a,b).\\]\n\nThese properties follow directly from the prime-exponent description. (uregina.ca)"
    },
    {
      "heading": "Computing the GCD",
      "text": "The principal method is the Euclidean algorithm, which avoids requiring prime factorizations. Its essential step is\n\n\\[\\gcd(a,b)=\\gcd(b,r), \\qquad a=qb+r.\\]\n\nA number dividing \\(a\\) and \\(b\\) also divides \\(r=a-qb\\); conversely, a number dividing \\(b\\) and \\(r\\) divides \\(a=qb+r\\). The two pairs therefore have exactly the same common divisors. (math.libretexts.org)\n\nFor nonnegative inputs with \\(b>0\\), choose \\(0\\le r<b\\), replace \\((a,b)\\) by \\((b,r)\\), and repeat until the second entry is zero. The decreasing positive remainders ensure termination. The last nonzero remainder is the GCD. For example,\n\n\\[\\begin{aligned} 252&=1\\cdot198+54,\\\\ 198&=3\\cdot54+36,\\\\ 54&=1\\cdot36+18,\\\\ 36&=2\\cdot18+0. \\end{aligned}\\]\n\nHence \\(\\gcd(252,198)=18\\). (math.libretexts.org)\n\nThe 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)"
    },
    {
      "heading": "Bézout’s identity",
      "text": "Bézout’s identity states that, for integers \\(a,b\\) not both zero, there are integers \\(x,y\\) such that\n\n\\[ax+by=\\gcd(a,b).\\]\n\nThe extended Euclidean algorithm computes these coefficients alongside the GCD, or obtains them by substituting backward through the remainder equations. For the preceding example,\n\n\\[\\begin{aligned} 18&=54-36\\\\ &=54-(198-3\\cdot54)\\\\ &=4(252-198)-198\\\\ &=4\\cdot252-5\\cdot198. \\end{aligned}\\]\n\nThus \\(x=4\\) and \\(y=-5\\). (math.libretexts.org)\n\nEvery integer linear combination \\(ax+by\\) 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 \\(ax+by\\). (math.libretexts.org)"
    },
    {
      "heading": "Applications",
      "text": "Reducing fractions. If \\(b\\ne0\\) and \\(d=\\gcd(a,b)\\), then\n\n\\[\\frac ab=\\frac{a/d}{b/d}.\\]\n\nThe resulting numerator and denominator are coprime, so the fraction is in lowest terms. For example, \\(18/24=3/4\\). This provides a standard representation of a rational number, with a positive denominator. (uregina.ca)\n\nInteger equations. A linear Diophantine equation\n\n\\[ax+by=c\\]\n\nhas integer solutions exactly when \\(\\gcd(a,b)\\mid c\\), provided \\(a,b\\) are not both zero. Necessity follows because the GCD divides every combination \\(ax+by\\); sufficiency follows by multiplying a Bézout identity by \\(c/\\gcd(a,b)\\). (math.uwaterloo.ca)\n\nModular inverses. In modular arithmetic, an integer \\(a\\) has a multiplicative inverse modulo \\(m>1\\) exactly when \\(\\gcd(a,m)=1\\). If \\(ax+my=1\\), then \\(ax\\equiv1\\pmod m\\), making \\(x\\) an inverse. For example, \\(3\\cdot5-7\\cdot2=1\\), so 5 is the inverse of 3 modulo 7. (ocw.mit.edu)"
    },
    {
      "heading": "Generalization to polynomials",
      "text": "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)\n\nPolynomial division with remainder supplies a Euclidean algorithm in which degrees decrease instead of integer magnitudes. For example, over the rational numbers,\n\n\\[\\gcd(x^2-1,x^2-3x+2)=x-1,\\]\n\nbecause the factorizations are \\((x-1)(x+1)\\) and \\((x-1)(x-2)\\). Polynomial GCD computations also extend to multivariate polynomials, although they require methods beyond this simple one-variable division procedure. (doc.sagemath.org)"
    },
    {
      "heading": "Historical background",
      "text": "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)"
    }
  ],
  "links": [
    "integer",
    "number-theory",
    "fundamental-theorem-of-arithmetic",
    "prime-number",
    "coprime-integers",
    "least-common-multiple",
    "euclidean-algorithm",
    "computer-science",
    "bezouts-identity",
    "extended-euclidean-algorithm",
    "linear-combination",
    "fraction",
    "rational-number",
    "diophantine-equation",
    "modular-arithmetic",
    "polynomial",
    "field-mathematics",
    "euclid",
    "euclids-elements"
  ],
  "sources": [
    {
      "title": "2: Greatest common divisor and least common multiple",
      "url": "https://math.libretexts.org/Courses/Mount_Royal_University/Abstract_Algebra_I/Chapter_1%3A_Integers/1.2%3A_Greatest_common_divisor_and_least_common_multiple"
    },
    {
      "title": "6: The Euclidean Algorithm",
      "url": "https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Yet_Another_Introductory_Number_Theory_Textbook_-_Cryptology_Emphasis_%28Poritz%29/01%3A_Well-Ordering_and_Division/1.06%3A_The_Euclidean_Algorithm"
    },
    {
      "title": "2: Euclidean algorithm and Bézout's algorithm",
      "url": "https://math.libretexts.org/Courses/Mount_Royal_University/Higher_Arithmetic/4%3A_Greatest_Common_Divisor_least_common_multiple_and_Euclidean_Algorithm/4.2%3A_Euclidean_algorithm_and__B%C3%A9zout%27s_algorithm"
    },
    {
      "title": "Miscellaneous arithmetic functions — SageMath",
      "url": "https://doc.sagemath.org/html/en/reference/rings_standard/sage/arith/misc.html"
    },
    {
      "title": "Math 101 Course Notes",
      "url": "https://uregina.ca/~hermana/Math101-8thEd.pdf"
    },
    {
      "title": "Greatest Common Divisor Algorithms — GNU MP",
      "url": "https://gmplib.org/manual/Greatest-Common-Divisor-Algorithms.html"
    },
    {
      "title": "MATH 145 Algebra, Lecture Notes",
      "url": "https://www.math.uwaterloo.ca/~snew/PMATH333/math145notes.pdf"
    },
    {
      "title": "Principles of Discrete Applied Mathematics, Modular Arithmetic and Elementary Algebra Notes",
      "url": "https://ocw.mit.edu/courses/18-310-principles-of-discrete-applied-mathematics-fall-2013/f348af83c95da4719f344b34ac310523_MIT18_310F13_Ch14.pdf"
    },
    {
      "title": "Univariate polynomials over number fields — SageMath",
      "url": "https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/polynomial_number_field.html"
    },
    {
      "title": "Univariate polynomial base class — SageMath",
      "url": "https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/polynomial_element.html"
    },
    {
      "title": "Polynomials — SageMath Constructions",
      "url": "https://doc.sagemath.org/html/en/constructions/polynomials.html"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}