All Topics  
Greatest common divisor

 

   Email Print
   Bookmark   Link






 

Greatest common divisor



 
 
In mathematics
Mathematics

Mathematics is the study of quantity, structure, space, change, and related topics of pattern and form. Mathematicians seek out patterns whether found in numbers, space, natural science, computers, imaginary abstractions, or elsewhere....
, the greatest common divisor (gcd), sometimes known as the greatest common factor (gcf) or highest common factor (hcf), of two non-zero integer
Integer

The integers are natural numbers including 0 and their negative and non-negative numberss . They are numbers that can be written without a fractional or decimal component, and fall within the set ....
s, is the largest positive integer that divides
Divisor

In mathematics, a divisor of an integer n, also called a factor of n, is an integer which evenly divides n without leaving a remainder....
 both numbers without remainder
Remainder

In arithmetic, when the result of the division of two integers cannot be expressed with an integer quotient, the remainder is the amount "left over."...
.



In plain language: in the problem 3 x 4 = 12, 3 and 4 are factors and 12 is the product or multiple. A common factor is a number which is a factor of two different problems; thus, in 1 x 4 the factors are 1, 2 and 4 (1 x 4 = 4; 2 x 2 = 4) and in 1 x 6 the factors are 1, 2, 3 and 6 (1 x 6 = 6; 2 x 3 = 6}; therefore the common factors of the two problems are 1 and 2, with 2 being the highest common factor.



This notion can be extended to polynomials, see greatest common divisor of two polynomials
Greatest common divisor of two polynomials

Informally, the greatest common divisor of two polynomial p and q is the "biggest" polynomial that divides evenly into both p and q....
.

Overview
The greatest common divisor of a and b is written as gcd(ab), or sometimes simply as (ab).






Discussion
Ask a question about 'Greatest common divisor'
Start a new discussion about 'Greatest common divisor'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In mathematics
Mathematics

Mathematics is the study of quantity, structure, space, change, and related topics of pattern and form. Mathematicians seek out patterns whether found in numbers, space, natural science, computers, imaginary abstractions, or elsewhere....
, the greatest common divisor (gcd), sometimes known as the greatest common factor (gcf) or highest common factor (hcf), of two non-zero integer
Integer

The integers are natural numbers including 0 and their negative and non-negative numberss . They are numbers that can be written without a fractional or decimal component, and fall within the set ....
s, is the largest positive integer that divides
Divisor

In mathematics, a divisor of an integer n, also called a factor of n, is an integer which evenly divides n without leaving a remainder....
 both numbers without remainder
Remainder

In arithmetic, when the result of the division of two integers cannot be expressed with an integer quotient, the remainder is the amount "left over."...
.



In plain language: in the problem 3 x 4 = 12, 3 and 4 are factors and 12 is the product or multiple. A common factor is a number which is a factor of two different problems; thus, in 1 x 4 the factors are 1, 2 and 4 (1 x 4 = 4; 2 x 2 = 4) and in 1 x 6 the factors are 1, 2, 3 and 6 (1 x 6 = 6; 2 x 3 = 6}; therefore the common factors of the two problems are 1 and 2, with 2 being the highest common factor.



This notion can be extended to polynomials, see greatest common divisor of two polynomials
Greatest common divisor of two polynomials

Informally, the greatest common divisor of two polynomial p and q is the "biggest" polynomial that divides evenly into both p and q....
.

Overview


The greatest common divisor of a and b is written as gcd(ab), or sometimes simply as (ab). For example, gcd(12, 18) = 6, gcd(−4, 14) = 2. Two numbers are called coprime
Coprime

In mathematics, the integers a and b are said to be coprime or relatively prime if they have no common divisor other than 1 or, equivalently, if their greatest common divisor is 1....
 or relatively prime if their greatest common divisor equals 1. For example, 9 and 28 are relatively prime.

The greatest common divisor is useful for reducing fraction
Fraction (mathematics)

A fraction is a number that can represent part of a whole.The earliest fractions were reciprocals of integers, symbols representing one half, one third, one quarter, and so on....
s to be in lowest terms
Irreducible fraction

An irreducible fraction is a vulgar fraction in which the numerator and denominator are smaller than those in any other equivalent vulgar fraction....
. For example, gcd(42, 56)=14, therefore,

Calculating the gcd


Greatest common divisors can in principle be computed by determining the prime factorizations of the two numbers and comparing factors, as in the following example: to compute gcd(18,84), we find the prime factorizations 18 = 2·32 and 84 = 22·3·7 and notice that the "overlap" of the two expressions is 2·3; so gcd(18,84) = 6. In practice, this method is only feasible for very small numbers; computing prime factorizations in general takes far too long.

A much more efficient method is the Euclidean algorithm
Euclidean algorithm

In number theory, the Euclidean algorithm is an algorithm to determine the greatest common divisor of two elements of any Euclidean domain . Its major significance is that it does not require factorization the two integers, and it is also significant in that it is one of the oldest algorithms known, dating back to the ancient Greeks....
, which uses the division algorithm
Division algorithm

The division algorithm is a theorem in mathematics which precisely expresses the outcome of the usual process of division of integers. The name is something of a misnomer, as it is a theorem, not an algorithm, i.e....
 in combination with the observation that the gcd of two numbers also divides their difference: divide 84 by 18 to get a quotient of 4 and a remainder of 12. Then divide 18 by 12 to get a quotient of 1 and a remainder of 6. Then divide 12 by 6 to get a remainder of 0, which means that 6 is the gcd.

The series of quotients generated by the Euclidean algorithm compose a continued fraction
Continued fraction

In mathematics, a continued fraction is an expression such aswhere a0 is an integer and all the other numbers ai are positive integers....
.

If a and b are not both zero, the greatest common divisor of a and b can be computed by using least common multiple
Least common multiple

In arithmetic and number theory, the least common multiple or lowest common multiple or smallest common multiple of two integers a and b is the smallest positive integer that is a multiple both of a and of b....
 (lcm) of a and b:

Keith Slavin has shown that for odd a=1:

which is a function that can be evaluated for complex b and Wolfgang Schramm has shown that: is an entire function
Entire function

In complex analysis, an entire function, also called an integral function, is a complex-valued Function that is holomorphic function everywhere on the whole complex plane....
 in the variable b for all positive integers a where is Ramanujan's sum
Ramanujan's sum

In number theory, a branch of mathematics, Ramanujan's sum, usually denoted cq, is a function of two positive integer variables q and n defined by the formula...
 . Marcelo Polezzi has shown that:

for positive integers a and b. Donald Knuth proved the following reduction:

for non-negative integers a and b, where a and b are not both zero.

Properties


  • Every common divisor of a and b is a divisor of gcd(ab).


  • gcd(ab), where a and b are not both zero, may be defined alternatively and equivalently as the smallest positive integer d which can be written in the form d = a·p + b·q where p and q are integers. This expression is called Bézout's identity
    Bézout's identity

    In number theory, B?zout's identity or B?zout's lemma is a linear equation diophantine equation. It states that if a and b are nonzero integers with greatest common divisor d, then there exist integers x and y such thatAdditionally, d is the least positive integer for which there are integer solutions x and...
    . Numbers p and q like this can be computed with the extended Euclidean algorithm
    Extended Euclidean algorithm

    The extended Euclidean algorithm is an extension to the Euclidean algorithm for finding the greatest common divisor of integers a and b: it also finds the integers x and y in B?zout's identity...
    .


  • gcd(a, 0) = |a|, for a ? 0, since any number is a divisor of 0, and the greatest divisor of a is |a|. This is usually used as the base case in the Euclidean algorithm.


  • If a divides the product b·c, and gcd(ab) = d, then a/d divides c.


  • If m is a non-negative integer, then gcd(m·am·b) = m·gcd(ab).


  • If m is any integer, then gcd(a + m·bb) = gcd(ab).


  • If m is a nonzero common divisor of a and b, then gcd(a/mb/m) = gcd(ab)/m.


  • The gcd is a multiplicative function
    Multiplicative function

    In number theory, a multiplicative function is an arithmetic function f of the positive integer n with the property that f = 1 and whenever...
     in the following sense: if a1 and a2 are relatively prime, then gcd(a1·a2b) = gcd(a1b)·gcd(a2b).


  • The gcd is a commutative
    Commutativity

    In mathematics, commutativity is the process to change the order of something without changing the end result. It is a fundamental property of many binary operations throughout mathematics, and many Mathematical proof depend on it....
     function: gcd(a, b) = gcd(b, a).


  • The gcd is an associative
    Associativity

    In mathematics, associativity is a property that a binary operation can have. It means that, within an expression containing two or more of the same associative operators in a row, the order that the operations are performed does not matter as long as the sequence of the operands is not changed....
     function: gcd(a, gcd(b, c)) = gcd(gcd(a, b), c).


  • The gcd of three numbers can be computed as gcd(abc) = gcd(gcd(ab), c), or in some different way by applying commutativity and associativity. This can be extended to any number of numbers.


  • gcd(ab) is closely related to the least common multiple
    Least common multiple

    In arithmetic and number theory, the least common multiple or lowest common multiple or smallest common multiple of two integers a and b is the smallest positive integer that is a multiple both of a and of b....
     lcm(ab): we have
gcd(ab)·lcm(ab) = a·b.
This formula is often used to compute least common multiples: one first computes the gcd with Euclid's algorithm and then divides the product of the given numbers by their gcd. The following versions of distributivity
Distributivity

In mathematics, and in particular in abstract algebra, distributivity is a property of binary operations that generalises the distributive law from elementary algebra....
 hold true:
gcd(a, lcm(bc)) = lcm(gcd(ab), gcd(ac)) lcm(a, gcd(bc)) = gcd(lcm(ab), lcm(ac)).

  • It is useful to define gcd(0, 0) = 0 and lcm(0, 0) = 0 because then the natural number
    Natural number

    In mathematics, a natural number can mean either an element of the Set = *n = = ? = ? ...
    s become a complete
    Complete lattice

    In mathematics, a complete lattice is a partially ordered set in which all subsets have both a supremum and an infimum . Complete lattices appear in many applications in mathematics and computer science....
     distributive
    Distributive lattice

    In mathematics, distributive lattices are lattice for which the operations of join and meet distributivity over each other. The prototypical examples of such structures are collections of sets for which the lattice operations can be given by set union and intersection ....
     lattice
    Lattice (order)

    In mathematics, a lattice is a partially ordered set in which subsets of any two elements have a unique supremum and an infimum . Lattices can also be characterized as algebraic structures satisfying certain Axiom identity ....
     with gcd as meet and lcm as join operation. This extension of the definition is also compatible with the generalization for commutative rings given below.


  • In a Cartesian coordinate system
    Cartesian coordinate system

    In mathematics, the Cartesian coordinate system is used to determine each Point uniquely in a Plane through two numbers, usually called the x-coordinate or abscissa and the y-coordinate or ordinate of the point....
    , gcd(ab) can be interpreted as the number of points with integral coordinates on the straight line joining the points (0, 0) and (ab), excluding (0, 0).


Probabilities and expected value


Let and be independently chosen at uniform random from the set . The limiting probability distribution
Probability distribution

In probability theory and statistics, a probability distribution identifies either the probability of each value of an unidentified random variable , or the probability of the value falling within a particular interval ....
, as , of is . This follows from the characterization of as the integer such that and and are coprime.

Clearly, the probability of two integers sharing a factor is . Thus, the normalization constant is given by the limiting probability that two integers are coprime, which is , where is the Riemann zeta function
Riemann zeta function

In mathematics, the Riemann zeta function, named after Germany mathematician Bernhard Riemann, is a prominent function of great significance in number theory because of its relation to the prime number theorem....
. Further, the limiting probability that independently chosen integers are coprime is . (See coprime
Coprime

In mathematics, the integers a and b are said to be coprime or relatively prime if they have no common divisor other than 1 or, equivalently, if their greatest common divisor is 1....
 for a derivation.)

Using this information, the expected value
Expected value

In probability theory and statistics, the expected value of a random variable is the Lebesgue integral of the random variable with respect to its probability measure....
 of the greatest common divisor function can be seen (informally) to not exist when . That is



This last summation is the Harmonic series
Harmonic series (mathematics)

In mathematics, the harmonic series is the Divergent series infinite series:Its name derives from the concept of overtones, or harmonics, in music: the wavelengths of the overtones of a vibrating string are 1/2, 1/3, 1/4, etc., of the string's fundamental wavelength....
, which diverges. However, when , the expected value is well-defined, and by the above argument, it is



For , this is approximately equal to 1.3684. For , it is approximately 1.1106.

if all integers x are limited as then the results can be extended to



where is the Hurwitz zeta function
Hurwitz zeta function

In mathematics, the Hurwitz zeta function, named after Adolf Hurwitz, is one of the many zeta functions. It is formally defined for complex number arguments s with Re>1 and q with Re>0 by...
.

if different 's are known for different then the lowest is taken.

The gcd in commutative rings


The greatest common divisor can more generally be defined for elements of an arbitrary commutative ring
Commutative ring

In ring theory, a branch of abstract algebra, a commutative ring is a Ring in which the multiplication operation is commutative. The study of commutative rings is called commutative algebra....
.

If R is a commutative ring, and a and b are in R, then an element d of R is called a common divisor of a and b if it divides both a and b (that is, if there are elements x and y in R such that d·x = a and d·y = b). If d is a common divisor of a and b, and every common divisor of a and b divides d, then d is called a greatest common divisor of a and b.

Note that with this definition, two elements a and b may very well have several greatest common divisors, or none at all. But if R is an integral domain
Integral domain

In abstract algebra, an integral domain is a commutative ring without zero divisors and with a multiplicative identity 1 not equal to 0, the additive identity....
 then any two gcd's of a and b must be associate elements. Also, if R is a unique factorization domain
Unique factorization domain

In mathematics, a unique factorization domain is, roughly speaking, a commutative ring in which every element, with special exceptions, can be uniquely written as a product of prime elements, analogous to the fundamental theorem of arithmetic for the integers....
, then any two elements have a gcd. If R is a Euclidean domain
Euclidean domain

In abstract algebra, a Euclidean domain is a type of Ring in which the Euclidean algorithm applies. Euclidean domains possess many important properties similar to the integers: for example, the fundamental theorem of arithmetic holds in any Euclidean domain....
 then a form of the Euclidean algorithm can be used to compute greatest common divisors.

The following is an example of an integral domain with two elements that do not have a gcd:

The elements and are two "maximal common divisors" (i.e. any common divisor which is a multiple of 2 is associated to 2, the same holds for ), but they are not associated, so there is no greatest common divisor of a and b.

Corresponding to the Bezout property we may, in any commutative ring, consider the collection of elements of the form , where p and q range over the ring. This is the ideal
Ideal (ring theory)

In ring theory, a branch of abstract algebra, an ideal is a special subset of a ring . The ideal concept generalizes in an appropriate way some important properties of integers like "even number" or "multiple of 3"....
 generated by a and b, and is denoted simply . In a ring all of whose ideals are principal (a principal ideal domain
Principal ideal domain

In abstract algebra, a principal ideal domain, or PID is an integral domain in which every ideal is principal ideal, i.e., can be generated by a single element....
 or PID), this ideal will be identical with the set of multiples of some ring element d; then this d is a greatest common divisor of a and b. But the ideal can be useful even when there is no greatest common divisor of a and b. (Indeed, Ernst Kummer
Ernst Kummer

Ernst Eduard Kummer was a Germany mathematician. Highly skilled in applied mathematics, Kummer trained German army officers in ballistics; afterwards, he taught for 10 years in a Gymnasium , where he inspired the mathematical career of Leopold Kronecker....
 used this ideal as a replacement for a gcd in his treatment of Fermat's Last Theorem
Fermat's Last Theorem

Fermat's Last Theorem is the name of the statement in number theory that states that:or, more precisely:In 1637 Pierre de Fermat wrote, in his copy of Claude Gaspard Bachet de M?ziriac's translation of the famous Arithmetica of Diophantus, "I have a truly marvellous proof of this proposition which this margin is too narrow to con...
, although he envisioned it as the set of multiples of some hypothetical, or ideal, ring element d, whence the ring-theoretic term.)

See also


  • Least common multiple
    Least common multiple

    In arithmetic and number theory, the least common multiple or lowest common multiple or smallest common multiple of two integers a and b is the smallest positive integer that is a multiple both of a and of b....
  • Lowest common denominator
    Lowest common denominator

    In mathematics, the lowest common denominator or least common denominator is the least common multiple of the denominators of a set of vulgar fractions....
  • Binary GCD algorithm
    Binary GCD algorithm

    The binary GCD algorithm is an algorithm which computes the greatest common divisor of two nonnegative integers. It gains a measure of efficiency over the ancient Euclidean algorithm by replacing divisions and multiplications with shifts, which are cheaper when operating on the binary representation used by modern computers....
  • Euclidean algorithm
    Euclidean algorithm

    In number theory, the Euclidean algorithm is an algorithm to determine the greatest common divisor of two elements of any Euclidean domain . Its major significance is that it does not require factorization the two integers, and it is also significant in that it is one of the oldest algorithms known, dating back to the ancient Greeks....
  • Extended Euclidean algorithm
    Extended Euclidean algorithm

    The extended Euclidean algorithm is an extension to the Euclidean algorithm for finding the greatest common divisor of integers a and b: it also finds the integers x and y in B?zout's identity...
  • Greatest common divisor of two polynomials
    Greatest common divisor of two polynomials

    Informally, the greatest common divisor of two polynomial p and q is the "biggest" polynomial that divides evenly into both p and q....


Further reading


  • Donald Knuth
    Donald Knuth

    Donald Ervin Knuth is a renowned computer science and Emeritus of the Art of Computer Programming at Stanford University.Author of the seminal multi-volume work The Art of Computer Programming , Knuth has been called the "father" of the run-time analysis, contributing to the development of, and systematizing formal mathematical techn...
    . The Art of Computer Programming, Volume 2: Seminumerical Algorithms, Third Edition. Addison-Wesley, 1997. ISBN 0-201-89684-2. Section 4.5.2: The Greatest Common Divisor, pp.333–356.
  • Thomas H. Cormen
    Thomas H. Cormen

    Thomas H. Cormen is the co-author of Introduction to Algorithms, along with Charles Leiserson, Ron Rivest, and Clifford Stein. He is a Full Professor of computer science at Dartmouth College and currently Chair of the Dartmouth College Writing Program....
    , Charles E. Leiserson
    Charles E. Leiserson

    Charles Eric Leiserson is a computer scientist, specializing in the theory of parallel computing and distributed computing, and particularly practical applications thereof; as part of this effort, he developed the Cilk multithreaded language....
    , Ronald L. Rivest, and Clifford Stein
    Clifford Stein

    Clifford Stein, a computer scientist, is currently a professor of industrial engineering and operations research at Columbia University in New York, NY, where he also holds an appointment in the Department of Computer Science....
    . Introduction to Algorithms
    Introduction to Algorithms

    Introduction to Algorithms is a book by Thomas H. Cormen, Charles E. Leiserson, Ron Rivest, and Clifford Stein. It is used as the textbook for algorithms courses at many universities....
    , Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 31.2: Greatest common divisor, pp.856–862.
  • Saunders MacLane and Garrett Birkhoff
    Garrett Birkhoff

    Garrett Birkhoff was an United States mathematician.The mathematician George Birkhoff was his father....
    . A Survey of Modern Algebra, Fourth Edition. MacMillan Publishing Co., 1977. ISBN 0-02-310070-2. 1-7: "The Euclidean Algorithm."


External links

  • , by Alexander Stepanov
    Alexander Stepanov

    Alexander Stepanov is the key person behind the C++ Standard Template Library, which he started to develop around 1993 while employed at HP Labs....