Greatest common divisor: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Peter Schmitt
(first sentence replaced by article, examples as "Tutorial")
mNo edit summary
 
(33 intermediate revisions by 4 users not shown)
Line 2: Line 2:


The '''greatest common divisor''' (often abbreviated to '''gcd''', or '''g.c.d.''',
The '''greatest common divisor''' (often abbreviated to '''gcd''', or '''g.c.d.''',
sometimes also called '''highest common factor''') of two or more natural numbers
sometimes also called '''highest common factor''') of two or more [[natural number]]s
is the the largest number which divides evenly both (or all) the numbers.
is the largest number which divides evenly both (or all) the numbers. Since 1 divides all numbers, and since a divisor of a number cannot be larger than that number, the greatest common divisor of some numbers is a number between 1 and the smallest of the numbers inclusive, and therefore can be determined (at least in principle) by testing finitely many numbers.
Since 1 divides all numbers, and since a divisor of a number cannot be larger than that number,
the greatest common divisor of some numbers is a number between 1 and the smallest of the numbers,
amd therefore can be determined (at least in principle) by testing finitely many numbers.


Numbers for which the greatest common divisor is 1 are called '''relatively prime'''.
Numbers for which the greatest common divisor is 1 are called '''relatively prime'''.
If (for three or more numbers) any two of them are relatively prime,
If (for three or more numbers) any two of them are relatively prime, they are called '''pairwise relatively prime'''.
they are called '''pairwise relatively prime'''.


The greatest common divisor of two numbers ''a'' and ''b''
The greatest common divisor of two numbers ''a'' and ''b''
usually is written as gcd(''a'',''b''), or, if no confusion is to be expected, simply as (''a'',''b'').
usually is written as gcd(''a'',''b''), or, if no confusion is to be expected, simply as (''a'',''b'').


For instance,
{{TOC|right}}
: (4,9)=1, (4,6)=2, and (4,12)=4,
 
: for 72 =2.2.2.3.3, 108 =2.2.3.3.3 there is (72,108) = 2.2.3.3 = 36,
== Finding the greatest common divisor ==
: for 6 =2.3, 10 =2.5, 15 =3.5 there is gcd(6,10,15) = 1, (6,10) = 2, (6,15) = 3, (10,15) = 5 <br> and thus 6, 10, and 15 are ''relatively prime'', but not ''pairwise'' relative prime.
: The same holds for 4,9,10 &mdash; (4,9) = (9,10) = (4,9,10) = 1, but (4,10) = 2 &mdash;,
: while 1 = (7,9) = (7,10) = (9,10) = (7,9,10) are ''pairwise relatively prime'', and therefore also relatively prime.


A theoretically important method to determine the greatest common divisor uses [[prime factorization]]:
A theoretically important method to determine the greatest common divisor uses [[prime factorization]]:
Line 28: Line 21:
However, since prime factorization is not efficient,
However, since prime factorization is not efficient,
this is at most practical for small numbers (or for numbers whose factorization is already known).
this is at most practical for small numbers (or for numbers whose factorization is already known).
This product expression shows that the greatest common divisor can be characterized by the following property:
The gcd is a common divisor, and every common divisor divides it evenly.


Fortunately, the [[Euclidean algorithm]] provides an efficient means to calculate the greatest common divisor.
Fortunately, the [[Euclidean algorithm]] provides an efficient means to calculate the greatest common divisor.
It also shows that the greatest common divisor can be expressed
It also shows that the greatest common divisor can be expressed  
as an integer linear combination of the numbers  (''a'',''b'') = ''ka'' + ''lb'' (with integers ''k'' and ''l'').
as an integer linear combination of the numbers  (''a'',''b'') = ''ra'' + ''sb'' (with integers ''r'' and ''s'').
Since every such linear combination is divisible by all divisors common to
Since every such linear combination is divisible by all divisors common to
''a'' and ''b'', this in turn shows that it is the ''smallest'' positive linear combination
''a'' and ''b'', this, in turn, shows that it is the ''smallest'' positive linear combination,
and thus (in the language of [[ring theory]])
and therefore (in the language of [[ring theory]])
the ideal generated by ''a'' and ''b'' is a principal ideal generated by (''a'',''b'').
the ideal generated by ''a'' and ''b'' is a principal ideal generated by (''a'',''b'').


The greatest common divisor is used to reduce fractions:
== Examples ==
Given some fraction ''p''/''q'', then  ''p''/(''p'',''q'') / ''q''/(''p'',''q'') is its reduced representation.


For instance,


== Tutorial ==
* (4,9) = 1, (4,6) = 2, and (4,12) = 4, because
 
:: the divisors of 4 for are '''1''',2,4; the divisors of 9 are '''1''',3,9; and the only common divisor and the gcd '''1''';
For example, the divisors of 60 are
:: the divisors of 4 for are 1,'''2''',4; the divisors of 6 are 1,'''2''',3,6; the common divisors are 1 and '''2''', and the gcd is '''2''';
 
:: the divisors of 4 for are 1,2,'''4'''; the divisors of 12 are 1,2,3,'''4''',6,12; the common divisors are 1,2,'''4''', and the gcd is '''4'''.
: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60,
 
and the divisors of 72 are
 
: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72.
 
The '''common divisors''' of 60 and 72 are the numbers that appear in both lists:
 
: 1, 2, 3, 4, 6, 12.
 
The '''greatest common divisor''' of 60 and 72 is therefore 12.  One writes "gcd(60,&nbsp;72) = 12", or simply "(60,&nbsp;72) = 12".
 
The greatest common divisor is used in reducing fractions to lowest terms, thus:
 
:<math>\frac{60}{72} = \frac{12 \times 5}{12 \times 6} = \frac{5}{6}.</math>
 
== An algorithm involving prime factorizations ==
 
One method of finding the greatest common divisor of two integers involves [[Unique factorization|factoring]] both into [[prime number]]s:
 
:<math> 60 = 2 \times 2 \times 3 \times 5,\,</math>
 
:<math> 72 = 2 \times 2 \times 2 \times 3 \times 3.\,</math>
 
Observe that the prime number 2 occurs twice in the factorization of 60, and three times in the factorization of 72.  One says that the ''multiplicity'' of that prime factor is 2 in the first case and 3 in the second. ("Multiplicity" means the number of times the prime factor appears in the factorization.)  For each prime factor, one sees which multiplicity is ''smaller'': the one in the factorization of 60 or the one in the factorization of 72:
 
: In the factorization of 60, the multiplicity of the prime factor 2 is 2.
: In the factorization of 72, the multiplicity of the prime factor 2 is 3.
: The smaller of those multiplicities is 2.
 
Next:
 
: In the factorization of 60, the multiplicity of the prime factor 3 is 1.
: In the factorization of 72, the multiplicity of the prime factor 3 is 2.
: The smaller of those multiplicities is 1.
 
Next:
 
: In the factorization of 60, the multiplicity of the prime factor 5 is 1.
: In the factorization of 72, the multiplicity of the prime factor 5 is 0.
: The smaller of those multiplicities is 0.
 
: All other prime numbers have multiplicity 0 in the factorization of both 60 and 72.
: The smaller of those two multiplicities (both 0) is 0.
 
Therefore
 
: the multiplicity of 2 in the factorization of the gcd is 2;
: the multiplicity of 3 in the factorization of the gcd is 1;
: the multiplicity of any other prime number in the factorization of the gcd is 0.
 
The gcd is therefore 2&nbsp;&times;&nbsp;2&nbsp;&times;&nbsp;3 = 12.
 
Here is another example: the problem is to find gcd(14280,&nbsp;1638).  We have
 
: 14280 = 2 &times; 2 &times; 2 &times; 3 &times; 5 &times; 7 &times; 17.
:  1638 = 2 &times; 3 &times; 3 &times; 7 &times; 13.
 
For the prime number 2, the multiplicities are 3 and 1; the smaller of those is 1.
 
For the prime number 3, the multiplicities are 1 and 2; the smaller of those is 1.


For the prime number 5, the multiplicities are 1 and 0; the smaller of those is 0.
* (72,108) = 36 because
:: the prime factorizations 72 = '''2''' • '''2''' • 2 • '''3''' • '''3''' and 108 = '''2''' • '''2''' • '''3''' • '''3''' • 3 have the common factors '''2''' • '''2''' • '''3''' • '''3''' = 36.


For the prime number 7, the multiplicities are 1 and 1; the smaller of those is 1.
* 6, 10, and 15 are ''relatively prime'', but not ''pairwise'' relatively prime, because
:: gcd(6,10,15) = 1, but (6,10) = 2, (6,15) = 3, (10,15) = 5, as can be seen either
::: from the prime factorizations 6 = 2 • 3, 10 = 2 • 5, 15 = 3 • 5 in which no prime occurs in all three products, or
::: from the lists of divisors: 1,2,3,6 for 6, and 1,2,5,10 for 10, and 1,3,5,15 for 15.


For the prime number 11, the multiplicities are 0 and 0; the smaller of those is 0.
* 7, 9, and 10 are ''relatively prime'', but not ''pairwise'' relatively prime, because
:: gcd(4,9,10) = 1, but (4,10) = 2 even though two pairs are (4,9) = (9,10) = 1 are relatively prime.


For the prime number 13, the multiplicities are 0 and 1; the smaller of those is 0.
* 7, 9, 10 are ''pairwise relatively prime'', and therefore also relatively prime
:: because (7,9) = (7,10) = (9,10) = (7,9,10) = 1.


And so on&mdash;for all larger prime numbers the multiplicity is 0.
''See also the [[/Tutorials|Tutorial]].''


Therefore gcd(14280,&nbsp;1638) = 2 &times; 3 &times; 7 = 42.
== Applications ==


== An algorithm not involving prime numbers ==
In elementary arithmetic, the greatest common divisor is used to simplify expressions
by reducing the size of numbers involved,
e.g., given some fraction ''p''/''q'', then  ''p''/(''p'',''q'') / ''q''/(''p'',''q'') is its reduced representation.
For instance:
: The reduced form of 9/12 is 3/4 because (9,12) = 3.
Similarly, equations can be simplified:
: The quadratic equation 9''x''<sup>2</sup> + 12''x'' = 0 is equivalent to 3''x''<sup>2</sup> + 4''x'' = 0.
Moreover, the gcd can be used to calculate the [[least common multiple]]:
lcm(''a'',''b'') = ''ab''/gcd(''a'',''b''):
: lcm(9,12) = 9•12 / gcd(9,12) = 108/3 = 36


When the prime factors of a number are large, the algorithm above may be inefficient.  [[Euclid's algorithm]] does not involve prime factorizations and runs fast in such cases.  It may be described as follows:
== Generalizations ==


: (1) Replace the larger of the two numbers with the remainder on division of the larger by the smaller.
The notion of [[divisibility]] can be generalized to the context of rings,
: (2) Repeat step (1) until one of the two numbers is 0.
the idea of a greatest common divisor, however, is not always applicable.
: (3) The one that is not 0 is the gcd.
<br>
But in [[Euclidean rings]],
i.e., in rings for which there is an analogue to the Euclidean algorithm,
a greatest common divisor does exist.
An important example is the ring of [[polynomial]]s:
The greatest common divisor of two polynomials is a common factor of greatest degree.
In this case the gcd is only unique up to a constant factor.
<br>
More generally, a greatest common divisor can be defined for rings with unique prime factorization.


For an example, let's find the greatest common divisor of the last pair of numbers we used above, (14280, 1638).
== Formulas ==
::14280 / 1638 = 8 remainder 1176. because <math>1638 \times 8</math> is 13104.
:Now we take the new pair of numbers (1638, 1176).
::1638 / 1176 = 1 remainder 462
:Now we have (1176,462).
::1176 / 462 = 2 remainder 252
:Now we have (462, 252).
::462 / 252 = 1 remainder 210.
:Now we have (252,210).
::252 / 210 = 1 remainder 42.
:Now we have (210,42).
::210 / 42 = 5 remainder 0.
:Now we have (42,0).


Therefore gcd(14280,1638) = 42.
; Bounds :  <math> 1 \le \mathop{\rm gcd} (a,b) \le \min(a,b) </math>


== See also ==
; gcd and lcm : <math> \mathop{\rm gcd} (a,b) \mathop{\rm lcm} (a,b) = ab </math>


* [[Least common multiple]]
; prime factor representation : <math> a = \prod_{p\ \rm prime} p^{a(p)} \ \textrm{\ and\ }\ b = \prod_{p\ \rm prime} p^{b(p)} \ \Rightarrow \  \mathop{\rm gcd}(a,b) = \prod_{p\ \rm prime} p^{\min(a(p),b(p))} </math>[[Category:Suggestion Bot Tag]]

Latest revision as of 16:01, 23 August 2024

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Tutorials [?]
 
This editable Main Article is under development and subject to a disclaimer.

The greatest common divisor (often abbreviated to gcd, or g.c.d., sometimes also called highest common factor) of two or more natural numbers is the largest number which divides evenly both (or all) the numbers. Since 1 divides all numbers, and since a divisor of a number cannot be larger than that number, the greatest common divisor of some numbers is a number between 1 and the smallest of the numbers inclusive, and therefore can be determined (at least in principle) by testing finitely many numbers.

Numbers for which the greatest common divisor is 1 are called relatively prime. If (for three or more numbers) any two of them are relatively prime, they are called pairwise relatively prime.

The greatest common divisor of two numbers a and b usually is written as gcd(a,b), or, if no confusion is to be expected, simply as (a,b).

Finding the greatest common divisor

A theoretically important method to determine the greatest common divisor uses prime factorization: Every prime factor of a common divisor must be a prime factor of all the numbers. The greatest common divisor therefore is the product of all common prime factors taken with the highest power common to all the numbers. However, since prime factorization is not efficient, this is at most practical for small numbers (or for numbers whose factorization is already known). This product expression shows that the greatest common divisor can be characterized by the following property: The gcd is a common divisor, and every common divisor divides it evenly.

Fortunately, the Euclidean algorithm provides an efficient means to calculate the greatest common divisor. It also shows that the greatest common divisor can be expressed as an integer linear combination of the numbers (a,b) = ra + sb (with integers r and s). Since every such linear combination is divisible by all divisors common to a and b, this, in turn, shows that it is the smallest positive linear combination, and therefore (in the language of ring theory) the ideal generated by a and b is a principal ideal generated by (a,b).

Examples

For instance,

  • (4,9) = 1, (4,6) = 2, and (4,12) = 4, because
the divisors of 4 for are 1,2,4; the divisors of 9 are 1,3,9; and the only common divisor and the gcd 1;
the divisors of 4 for are 1,2,4; the divisors of 6 are 1,2,3,6; the common divisors are 1 and 2, and the gcd is 2;
the divisors of 4 for are 1,2,4; the divisors of 12 are 1,2,3,4,6,12; the common divisors are 1,2,4, and the gcd is 4.
  • (72,108) = 36 because
the prime factorizations 72 = 22 • 2 • 33 and 108 = 2233 • 3 have the common factors 2233 = 36.
  • 6, 10, and 15 are relatively prime, but not pairwise relatively prime, because
gcd(6,10,15) = 1, but (6,10) = 2, (6,15) = 3, (10,15) = 5, as can be seen either
from the prime factorizations 6 = 2 • 3, 10 = 2 • 5, 15 = 3 • 5 in which no prime occurs in all three products, or
from the lists of divisors: 1,2,3,6 for 6, and 1,2,5,10 for 10, and 1,3,5,15 for 15.
  • 7, 9, and 10 are relatively prime, but not pairwise relatively prime, because
gcd(4,9,10) = 1, but (4,10) = 2 even though two pairs are (4,9) = (9,10) = 1 are relatively prime.
  • 7, 9, 10 are pairwise relatively prime, and therefore also relatively prime
because (7,9) = (7,10) = (9,10) = (7,9,10) = 1.

See also the Tutorial.

Applications

In elementary arithmetic, the greatest common divisor is used to simplify expressions by reducing the size of numbers involved, e.g., given some fraction p/q, then p/(p,q) / q/(p,q) is its reduced representation. For instance:

The reduced form of 9/12 is 3/4 because (9,12) = 3.

Similarly, equations can be simplified:

The quadratic equation 9x2 + 12x = 0 is equivalent to 3x2 + 4x = 0.

Moreover, the gcd can be used to calculate the least common multiple: lcm(a,b) = ab/gcd(a,b):

lcm(9,12) = 9•12 / gcd(9,12) = 108/3 = 36

Generalizations

The notion of divisibility can be generalized to the context of rings, the idea of a greatest common divisor, however, is not always applicable.
But in Euclidean rings, i.e., in rings for which there is an analogue to the Euclidean algorithm, a greatest common divisor does exist. An important example is the ring of polynomials: The greatest common divisor of two polynomials is a common factor of greatest degree. In this case the gcd is only unique up to a constant factor.
More generally, a greatest common divisor can be defined for rings with unique prime factorization.

Formulas

Bounds
gcd and lcm
prime factor representation