Articles

1.5: The Greatest Common Divisor - Mathematics

1.5: The Greatest Common Divisor - Mathematics



We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.

In this section we define the greatest common divisor (gcd) of two integers and discuss its properties. We also prove that the greatest common divisor of two integers is a linear combination of these integers.

Two integers (a) and (b), not both (0), can have only finitely many divisors (see Exercise [exer:sizeofdivisors]), and thus can have only finitely many divisors in common. In this section, we are interested in the greatest of these common divisors.

Given (a,binZ), not both zero, the greatest common divisor is the largest integer that divides both (a) and (b), and is written (gcd(a,b)) (or sometimes just ((a,b))).

When it makes some formulæ simpler, we will write (gcd(0,0)=0).

[eg:gcda] The greatest common divisor of 24 and 18 is 6. In other words (gcd(24,18)=6).

(a,binZ) are said to be relatively prime if (gcd(a,b)=1).

[eg:gcdb] The greatest common divisor of 9 and 16 is 1, thus they are relatively prime.

Note that every integer has positive and negative divisors. If (a) is a positive divisor of (m), then (-a) is also a divisor of (m). Therefore by our definition of the greatest common divisor, we can see that (gcd(a,b)=gcd(|a|, |b|)).

We can use the gcd of two integers to make relatively prime integers:

[thm:dividebygcd] If (a,binZ) have (gcd(a,b)=d) then (gcd(a/d,b/d)=1).

Fix (a,binZ). We will show that (a/d) and (b/d) have no common positive divisors other than (1). Let (kinNN) be a divisor of both (a/d) and (b/d), so (exists m,ninNN) such that [a/d=km hspace{0.3 cm}mbox{and} b/d=kn] Thus we get that [a=kmd hspace{0.3 cm}mbox{and} b=knd.] Hence (kd) is a common divisor of both (a) and (b). Also, (kdgeq d). However, (d) is the greatest common divisor of (a) and (b). As a result, we get that (k=1).

The next theorem shows that the greatest common divisor of two integers does not change when we add a multiple of one of the two integers to the other.

Let (a,b,cinZ). Then (gcd(a,b)=gcd(a+cb,b)).

We will show that every divisor of (a) and (b) is also a divisor of (a+cb) and (b) and vise versa. Hence they have exactly the same divisors. So we get that the greatest common divisor of (a) and (b) will also be the greatest common divisor of (a+cb) and (b). Let (k) be a common divisor of (a) and (b). By Theorem [thm:divisibilitylincombs], (k mid (a+cb)) and hence (k) is a divisor of (a+cb). Now assume that (l) is a common divisor of (a+cb) and (b). Also by Theorem [thm:divisibilitylincombs] we have, [lmid ((a+cb)-cb)=a.] As a result, (l) is a common divisor of (a) and (b) and the result follows.

[eg:gcdc] Notice that (gcd(4,14)=gcd(4,14-3cdot 4)=gcd(4,2)=2).

We now present a theorem which proves that the greatest common divisor of two integers can be written as a linear combination of the two integers.

[thm:gcdislincomb] Let (a,binZ) not both be zero. Then (gcd(a,b)) is the smallest natural number which is of the form (d=ma+nb) for some (m,ninZ).

Assume without loss of generality that (a,binNN) are positive integers. Consider the set [S={dinNNmid d=ma+nb ext{ for some }m,ninZ} .] (S) is non-empty since (a=1cdot a+0cdot b) and (b=0cdot a+1cdot b) are both in (S). Let (dinNN) be the least element of (S), whose existence is guaranteed by the well-ordering principle. Notice (d=ma+nb) for some (m,ninZ), since (din S). We still must prove that (d) divides both (a) and (b) and that it is the greatest such common divisor.

By the division algorithm, (exists q,rinZ) such that [a=qd+r, 0leq r

The same sort of argument will show that (dmid b).

Now notice that if there is a divisor (c) that divides both (a) and (b). Then (c) divides any linear combination of (a) and (b) by Theorem [thm:divisibilitylincombs]. Hence (cmid d). This proves that any common divisor of (a) and (b) divides (d). Hence (cleq d), and (d) is the greatest common divisor.

There is a simple application of this which will be very useful in the future:

[cor:intlincombrelprime] If (a,binZ) are relatively prime, then (exists m,ninZ) such that (ma+nb=1).

For some (ninNN), let (a_1,a_2,dots,a_ninZ) not be all (0). The greatest common divisor of these integers is the largest integer that divides all of them, and is denoted (gcd(a_1,dots,a_n)).

For some (ninNN), (a_1,a_2,dots,a_ninZ) are said to be mutually relatively prime if (gcd(a_1,a_2,dots,a_n)=1).

[eg:mutrelprime] The integers (3, 6, 7) are mutually relatively prime since ((3,6,7)=1) although ((3,6)=3).

For some (ninNN), (a_1,a_2,dots,a_ninZ) are called pairwise relatively prime if (forall i,jinNN) such that (ile n), (jle n), and (i eq j), we have (gcd(a_i,a_j)=1).

[eg:pairwiserelprime] The integers (3,14,25) are pairwise relatively prime. Notice also that these integers are mutually relatively prime.

For (ninNN) and (a_1,dots,a_ninZ), if (a_1,a_2,dots,a_n) are pairwise relatively prime then they are mutually relatively prime.

Exercises for §5

Find the greatest common divisor of 15 and 35.

Find the greatest common divisor of 100 and 104.

Find the greatest common divisor of -30 and 95.

Let (minNN). Find the greatest common divisor of (m) and (m+1).

Let (minNN), find the greatest common divisor of (m) and (m+2).

Show that if (m,ninZ) have (gcd(m,n)=1), then (gcd(m+n,m-n)=1) or (2).

Show that if (minNN), then (3m+2) and (5m+3) are relatively prime.

Show that if (a,binZ) are relatively prime, then (gcd(a+2b,2a+b)=1) or (3).

Show that if (a_1,a_2,dots,a_ninZ) are not all (0) and (cinNN), then (gcd(ca_1,ca_2,dots,ca_n)=ccdotgcd(a_1,a_2,dots,a_n).)


Greatest common divisor (GCD) - math problems


    The classroom is 9 meters long. The width of the classroom is smaller and can be passed in equally long steps of 55 CM or 70 CM. Determine the width of the classroom.
    The land, which has dimensions of 220 m and 308 m, the owner wants to divide into equally large square plots with the largest possible area. How long will one side of the plot be?
    The gardening colony with dimensions of 180 m and 300 m is to be completely divided into equally large square areas with the largest possible area. Calculate how many such square areas can be obtained and determine the side length of the square.
    In the two dining rooms in the recreational building, there are equally arranged chairs around the tables. A maximum of 78 people can dine in the first dining room and 54 people in the second. How many chairs can be around one table?
    From two sticks 240 cm and 210 cm long, it is necessary to cut the longest possible pegs for flowers so that no residues remain. How many pegs will it be?
    The wooden block measures 12 cm, 24 cm, and 30 cm. Peter wants to cut it into several identical cubes. At least how many cubes can he get?
    From the smallest number of identical cubes whose edge length is expressed by a natural number, can we build a block with dimensions 12dm x 16dm x 20dm?
    How many of the largest square sheets did the plumber cut the honeycomb from 16 dm and 96 dm?
    The children's home received a gift to Nicholas of 54 oranges, 81 chocolate figurines, and 135 apples. Every child received the same gift and nothing was left. a) How many packages could be prepared? b) what did the children find in the package?
    Find quotient before the bracket - the largest divisor 51 a + 34 b + 68 121y-99z-33
    At 6 am, three bus lines are departing from the station. The first line has an interval of 24 minutes. The second line has an interval of 15 minutes. The third line runs at regular intervals of more than 1 minute. The third line runs at the same time as t
    Find all common divisors of numbers 30 and 45.
    What is the smallest length of a string that we can cut into 18 equal parts and even 27 equal parts (in decimeters)?
    Write seven 4-digit numbers that are divisible by 3 and at the same time by 4.
    The tickets to the show cost some integer number greater than 1. Also, the sum of the price of the children's and adult tickets, as well as their product, was the power of the prime number. Find all possible ticket prices.
    Roman walked on the bridge. When he heard the whistle, he turned and saw running Kamil at the beginning of the bridge. If he went to him, they would meet in the middle of the bridge. Roman, however, rushed and so did not want to waste time returning 150m.
    A large gear will be used to turn a smaller gear. The large gear will make 75 revolutions per minute. The smaller gear must make 384 revolutions per minute. Find the smallest number of teeth each gear could have. [Hint: Use either GCF or LCM. ]
    There are given the number C = 281, D = 201. Find the highest natural number S so that the C:S, D:S are with the remainder of 1,
    Divide a rectangular paper with dimensions 220mm and 308mm into squares of the same size so that they are as large as possible. Specify the length of the side of the square.
    Four poplars are growing along the way. The distances between them are 35 m, 14 m, and 91 m. At least how many poplars need to be dropped to create the same spacing between the trees? How many meters will it be?

Practice

Listing the Factors

Questions

  1. Find the greatest common factor of 18 and 27.
  2. Find the greatest common factor of 25, 75, and 125.
  3. Find the greatest common factor of 19 and 32.

Solutions

  1. The positive factors of 18 are 1, 2, 3, 6, 9, and 18.
    The positive factors of 27 are 1, 3, 9, and 27.
    The greatest number that appears in both lists is 9, so that is the greatest common factor.
  2. The positive factors of 25 are 1, 5, and 25.
    The positive factors of 75 are 1, 3, 5, 25, and 75.
    The positive factors of 125 are 1, 5, 25, and 125.
    The greatest number in all three lists is 25, so that is the greatest common factor.
  3. The positive factors of 19 are 1 and 19.
    The positive factors of 32 are 1, 2, 4, 8, 16, and 32.
    The greatest and only number that appears in both lists is 1, so that is the greatest common factor. Therefore, 19 and 32 are coprime.

Using Prime Factorization

Questions

  1. Find the greatest common factor of 1272 and 294.
  2. Find the greatest common factor of 900, 360, and 729.
  3. Find the greatest common factor of 72, 144, 258, and 824.

Solutions

  1. The prime factorization of 1272 is 2x2x2x3x53.
    The prime factorization of 294 is 2x3x7x7.
    Both 1272 and 294 contain one 2 and one 3, so the greatest common factor is 2ࡩ=6.
  2. The prime factorization of 900 is 2x2x3x3x5x5.
    The prime factorization of 360 is 2x2x2x3x3x5.
    The prime factorization of 729 is 3x3x3x3x3x3.
    All three factorized forms include two 3s, so the greatest common factor is 3ࡩ=9.
  3. The prime factorization of 72 is 2x2x2x3x3.
    The prime factorization of 144 is 2x2x2x2x3x3.
    The prime factorization of 258 is 2x3x43.
    The prime factorization of 824 is 2x2x2x103.

In this case, the only number that appears in all four factorized forms is 2, which is the greatest common factor.


The Pulverizer

We will get a lot of mileage out of the following key fact:

The greatest common divisor of (a) and (b) is a linear combination of (a) and (b). That is,

for some integers (s) and (t).

We already know from Lemma 8.1.2.2 that every linear combination of (a) and (b) is divisible by any common factor of (a) and (b), so it is certainly divisible by the greatest of these common divisors. Since any constant multiple of a linear combination is also a linear combination, Theorem 8.2.2 implies that any multiple of the gcd is a linear combination, giving:

Corollary 8.2.3. An integer is a linear combination of (a) and (b) iff it is a multiple of ( ext(a, b)).

We&rsquoll prove Theorem 8.2.2 directly by explaining how to find (s) and (t). This job is tackled by a mathematical tool that dates back to sixth-century India, where it was called kuttak, which means &ldquoThe Pulverizer.&rdquo Today, the Pulverizer is more commonly known as &ldquothe extended Euclidean gcd algorithm,&rdquo because it is so close to Euclid&rsquos algorithm.

For example, following Euclid&rsquos algorithm, we can compute the gcd of 259 and 70 as follows:

The Pulverizer goes through the same steps, but requires some extra bookkeeping along the way: as we compute ( ext(a, b)), we keep track of how to write each of the remainders (49, 21, and 7, in the example) as a linear combination of (a) and (b). This is worthwhile, because our objective is to write the last nonzero remainder, which is the GCD, as such a linear combination. For our example, here is this extra bookkeeping:

We began by initializing two variables, (x = a) and (y = b). In the first two columns above, we carried out Euclid&rsquos algorithm. At each step, we computed ( ext(x, y)) which equals (x - ext(x, y) cdot y). Then, in this linear combination of (x) and (y), we replaced (x) and (y) by equivalent linear combinations of (a) and (b), which we already had computed. After simplifying, we were left with a linear combination of (a) and (b) equal to ( ext(x, y)), as desired. The final solution is boxed.

This should make it pretty clear how and why the Pulverizer works. If you have doubts, it may help to work through Problem 8.13, where the Pulverizer is formalized as a state machine and then verified using an invariant that is an extension of the one used for Euclid&rsquos algorithm.

Since the Pulverizer requires only a little more computation than Euclid&rsquos algorithm, you can &ldquopulverize&rdquo very large numbers very quickly by using this algorithm. As we will soon see, its speed makes the Pulverizer a very useful tool in the field of cryptography.

Now we can restate the Water Jugs Lemma 8.1.5 in terms of the greatest common divisor:

Corollary 8.2.4. Suppose that we have water jugs with capacities (a) and (b). Then the amount of water in each jug is always a multiple of ( ext(a, b)).

For example, there is no way to form 4 gallons using 3- and 6-gallon jugs, because 4 is not a multiple of ( ext(3, 6) = 3).


Euclid's Algorithm for Greatest Common Divisor

As per Euclid's algorithm for the greatest common divisor, the GCD of two positive integers (a, b) can be calculated as:

  • If a = 0, then GCD (a, b) = b as GCD (0, b) = b.
  • If b = 0, then GCD (a, b) = a as GCD (a, 0) = a.
  • If both a≠0 and b≠0, we write 'a' in quotient remainder form (a = b×q + r) where q is the quotient and r is the remainder, and a>b.
  • Find the GCD (b, r) as GCD (b, r) = GCD (a, b)
  • We repeat this process until we get the remainder as 0.

Example: Find the GCD of 12 and 10 using Euclid's Algorithm.
Solution: The GCD of 12 and 10 can be found using the below steps:
a = 12 and b = 10
a≠0 and b≠0
In quotient remainder form we can write 12 = 10 × 1 + 2
Thus, GCD (10, 2) is to be found, as GCD(12, 10) = GCD (10, 2)

Now, a = 10 and b = 2
a≠0 and b≠0
In quotient remainder form we can write 10 = 2 × 5 + 0
Thus, GCD (2,0) is to be found, as GCD(10, 2) = GCD (2, 0)

Now, a = 2 and b = 0
a≠0 and b=0
Thus, GCD (2,0) = 2

GCD (12, 10) = GCD (10, 2) = GCD (2, 0) = 2

Thus, GCD of 12 and 10 is 2.

Euclid's algorithm is very useful to find GCD of larger numbers, as in this we can easily break down numbers into smaller numbers to find the greatest common divisor.

Topics Related to Greatest Common Divisor

Check out these interesting articles to know more about the greatest common divisor (GCD) and its related topics.


Greatest Common Divisor Calculator

The GCD calculator allows you to quickly find the greatest common divisor of a set of numbers. You may enter between two and ten non-zero integers between -2147483648 and 2147483647. The numbers must be separated by commas, spaces or tabs or may be entered on separate lines.

Press the button 'Calculate GCD' to start the calculation or 'Reset' to empty the form and start again.

Like for many other tools on this website, your browser must be configured to allow javascript for the program to function.

What is the greatest common divisor?

The greatest common divisor (also known as greatest common factor, highest common divisor or highest common factor) of a set of numbers is the largest positive integer number that devides all the numbers in the set without remainder. It is the biggest multiple of all numbers in the set.

The GCD is most often calculated for two numbers, when it is used to reduce fractions to their lowest terms. When the greatest common divisor of two numbers is 1, the two numbers are said to be coprime or relatively prime.

How is the greatest common divisor calculated?

This calculator uses Euclid's algorithm. To find out more about the Euclid's algorithm or the GCD, see this Wikipedia article.

The GCD may also be calculated using the least common multiple using this formula:


One of the most useful things is when we want to simplify a fraction:

Example: How can we simplify 1230?

Earlier we found that the Common Factors of 12 and 30 are 1, 2, 3 and 6, and so the Greatest Common Factor is 6.

So the largest number we can divide both 12 and 30 exactly by is 6, like this:

÷ 6
1230 = 25
÷ 6

The Greatest Common Factor of 12 and 30 is 6.

And so 1230 can be simplified to 25


We will first find the prime factorization of 1 and 5. After we will calculate the factors of 1 and 5 and find the biggest common factor number .

Step-2: Prime Factorization of 5

Prime factors of 5 are 5. Prime factorization of 5 in exponential form is:

Step-3: Factors of 1

List of positive integer factors of 1 that divides 1 without a remainder.

Step-4: Factors of 5

List of positive integer factors of 5 that divides 1 without a remainder.

Final Step: Biggest Common Factor Number

We found the factors and prime factorization of 1 and 5. The biggest common factor number is the GCF number.
So the greatest common factor 1 and 5 is 1.


Relationship to least common multiple

The product of the greatest common divisor and least common multiple of two numbers is equal to the product of the two numbers. Thus, one of the easiest (and most systematic) ways to find the least common multiple is to compute the greatest common divisor and then divide the product of the numbers by that value. This relationship is evident when using the prime factorization method of calculating the greatest common factor and least common multiple (using prime factorization, the divisors with the greatest powers are multiplied together), as all prime divisors are either used in the GCF or the LCM.


Greatest Common Factor (GCF) Worksheets

A large collection of GCF worksheets is meticulously drafted for students in grade 5 through grade 8. GCF is also known as 'greatest common divisor'(GCD), 'highest common factor'(HCF), 'greatest common measure'(GCM) or 'highest common divisor'(HCD). Download and print these GCF worksheets to find the GCF of two numbers, three numbers and more. Try some of these handouts for free!

List the factors for each pair of numbers. Then, compare to determine the GCF of the two numbers. The printable worksheets are categorized into three levels based on the range of numbers.

Use the prime factorization method to find the GCF for each pair of numbers. This batch of multi-level worksheet pdfs contains a total of 150 problems for 5th grade and 6th grade students. Use the answer key to validate your solutions.

Write down the factors for each pair of numbers in the Venn diagram. Then, list out the common factors in the intersection. The largest factor listed in the overlapping region is the GCF. This set includes numbers up to 25.

Brighten your math class by using Venn Diagrams to find the GCF of two numbers. Featuring numbers up to 99, this compilation requires learners to list out the factors, place the common factors in the overlapping region, and find the GCF.

Find the GCF for the numerator and the denominator of the given fraction in this set of printable worksheets. Then, reduce the fraction to its lowest term by dividing the numerator and denominator by the GCF. Numbers up to 25 are included in this section.

Facilitate better understanding of GCF by reviewing your skill with this bundle of printable worksheets that features numbers up to 99. Practice finding the GCF and simplifying the fraction using the GCF.

In this bunch of 7th grade and 8th grade pdf worksheets, determine the GCF for the set of three numbers. Apply prime factorization method to list out the common factors. Multiply the common factors to obtain the GCF of the three numbers.

It’s time to get acquainted with GCF of three numbers by working out the exercises in these pdfs covering numbers up to 99. Work out the GCF by finding the product of the prime factors common to all three numbers.

Gain an in-depth knowledge in finding the Greatest Common Factor of polynomials with these high school worksheets available in easy and moderate levels, find the GCF of two or three monomials, GCF of polynomials, find the GCF using the division method and more!


Contents

Definition Edit

The greatest common divisor (GCD) of two nonzero integers a and b 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) . [9]

This definition also applies when one of a and b is zero. In this case, the GCD is the absolute value of the non zero integer: gcd(a, 0) = gcd(0, a) = | a | . This case is important as the terminating step of the Euclidean algorithm.

The above definition cannot be used for defining gcd(0, 0) , since 0 × n = 0 , and zero thus has no greatest divisor. 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> . [10] [11] [12] This convention is followed by many computer algebra systems. [13] Nonetheless, some authors leave gcd(0, 0) undefined. [14]

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 Edit

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

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

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

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 Edit

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

A geometric view Edit

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).

Reducing fractions Edit

The greatest common divisor is useful for reducing fractions to the lowest terms. [16] For example, gcd(42, 56) = 14, therefore,

Least common multiple Edit

The greatest common divisor can be used to find the least common multiple of two numbers when the greatest common divisor is known, using the relation, [1]

Using prime factorizations Edit

Greatest common divisors can be computed by determining the prime factorizations of the two numbers and comparing factors. For example, to compute gcd(48, 180), we find the prime factorizations 48 = 2 4 · 3 1 and 180 = 2 2 · 3 2 · 5 1 the GCD is then 2 min(4,2) · 3 min(1,2) · 5 min(0,1) = 2 2 · 3 1 · 5 0 = 12, as shown in the Venn diagram. The corresponding LCM is then 2 max(4,2) · 3 max(1,2) · 5 max(0,1) = 2 4 · 3 2 · 5 1 = 720.

In practice, this method is only feasible for small numbers, as computing prime factorizations takes too long.

Euclid's algorithm Edit

The method introduced by Euclid for computing greatest common divisors is based on the fact that, given two positive integers a and b such that a > b , the common divisors of a and b are the same as the common divisors of ab and b .

So, Euclid's method for computing the greatest common divisor of two positive integers consists of replacing the larger number by the difference of the numbers, and repeating this until the two numbers are equal: that is their greatest common divisor.

For example, to compute gcd(48,18) , one proceeds as follows:

This method can be very slow if one number is much larger than the other. So, the variant that follows is generally preferred.

Euclidean algorithm Edit

A more efficient method is the Euclidean algorithm, a variant in which the difference of the two numbers a and b is replaced by the remainder of the Euclidean division (also called division with remainder) of a by b .

Denoting this remainder as a mod b , the algorithm replaces (a, b) by (b, a mod b) repeatedly until the pair is (d, 0) , where d is the greatest common divisor.

For example, to compute gcd(48,18), the computation is as follows:

This again gives gcd(48, 18) = 6 .

Lehmer's GCD algorithm Edit

Lehmer's algorithm is based on the observation that the initial quotients produced by Euclid's algorithm can be determined based on only the first few digits this is useful for numbers that are larger than a computer word. In essence, one extracts initial digits, typically forming one or two computer words, and runs Euclid's algorithms on these smaller numbers, as long as it is guaranteed that the quotients are the same with those that would be obtained with the original numbers. Those quotients are collected into a small 2-by-2 transformation matrix (that is a matrix of single-word integers), for using them all at once for reducing the original numbers [ clarification needed ] . This process is repeated until numbers are small enough that the binary algorithm (see below) is more efficient.

This algorithm improves speed, because it reduces the number of operations on very large numbers, and can use hardware arithmetic for most operations. In fact, most of the quotients are very small, so a fair number of steps of the Euclidean algorithm can be collected in a 2-by-2 matrix of single-word integers. When Lehmer's algorithm encounters a quotient that is too large, it must fall back to one iteration of Euclidean algorithm, with a Euclidean division of large numbers.

Binary GCD algorithm Edit

The binary GCD algorithm uses only subtraction and division by 2. The method is as follows: Let a and b be the two non-negative integers. Let the integer d be 0. There are five possibilities:

As gcd(a, a) = a, the desired GCD is a × 2 d (as a and b are changed in the other cases, and d records the number of times that a and b have been both divided by 2 in the next step, the GCD of the initial pair is the product of a and 2 d ).

Then 2 is a common divisor. Divide both a and b by 2, increment d by 1 to record the number of times 2 is a common divisor and continue.

Then 2 is not a common divisor. Divide a by 2 and continue.

Then 2 is not a common divisor. Divide b by 2 and continue.

As gcd(a,b) = gcd(b,a), if a < b then exchange a and b. The number c = ab is positive and smaller than a. Any number that divides a and b must also divide c so every common divisor of a and b is also a common divisor of b and c. Similarly, a = b + c and every common divisor of b and c is also a common divisor of a and b. So the two pairs (a, b) and (b, c) have the same common divisors, and thus gcd(a,b) = gcd(b,c). Moreover, as a and b are both odd, c is even, the process can be continued with the pair (a, b) replaced by the smaller numbers (c/2, b) without changing the GCD.

Each of the above steps reduces at least one of a and b while leaving them non-negative and so can only be repeated a finite number of times. Thus eventually the process results in a = b, the stopping case. Then the GCD is a × 2 d .

Example: (a, b, d) = (48, 18, 0) → (24, 9, 1) → (12, 9, 1) → (6, 9, 1) → (3, 9, 1) → (3, 3, 1) the original GCD is thus the product 6 of 2 d = 2 1 and a= b= 3.

The binary GCD algorithm is particularly easy to implement on binary computers. Its computational complexity is

The computational complexity is usually given in terms of the length n of the input. Here, this length is n = log ⁡ a + log ⁡ b , and the complexity is thus

Other methods Edit

If a and b are both nonzero, the greatest common divisor of a and b can be computed by using least common multiple (LCM) of a and b:

but more commonly the LCM is computed from the GCD.

which generalizes to a and b rational numbers or commensurable real numbers.

Keith Slavin has shown that for odd a ≥ 1:

which is a function that can be evaluated for complex b. [18] Wolfgang Schramm has shown that

is an entire function in the variable b for all positive integers a where cd(k) is Ramanujan's sum. [19]

Complexity Edit

The computational complexity of the computation of greatest common divisors has been widely studied. [20] If one uses the Euclidean algorithm and the elementary algorithms for multiplication and division, the computation of the greatest common divisor of two integers of at most n bits is O ( n 2 ) . ).> This means that the computation of greatest common divisor has, up to a constant factor, the same complexity as the multiplication.

However, if a fast multiplication algorithm is used, one may modify the Euclidean algorithm for improving the complexity, but the computation of a greatest common divisor becomes slower than the multiplication. More precisely, if the multiplication of two integers of n bits takes a time of T(n) , then the fastest known algorithm for greatest common divisor has a complexity O ( T ( n ) log ⁡ n ) . This implies that the fastest known algorithm has a complexity of O ( n ( log ⁡ n ) 2 ) . ight).>

Previous complexities are valid for the usual models of computation, specifically multitape Turing machines and random-access machines.

The computation of the greatest common divisors belongs thus to the class of problems solvable in quasilinear time. A fortiori, the corresponding decision problem belongs to the class P of problems solvable in polynomial time. The GCD problem is not known to be in NC, and so there is no known way to parallelize it efficiently nor is it known to be P-complete, which would imply that it is unlikely to be possible to efficiently parallelize GCD computation. Shallcross et al. showed that a related problem (EUGCD, determining the remainder sequence arising during the Euclidean algorithm) is NC-equivalent to the problem of integer linear programming with two variables if either problem is in NC or is P-complete, the other is as well. [21] Since NC contains NL, it is also unknown whether a space-efficient algorithm for computing the GCD exists, even for nondeterministic Turing machines.

Although the problem is not known to be in NC, parallel algorithms asymptotically faster than the Euclidean algorithm exist the fastest known deterministic algorithm is by Chor and Goldreich, which (in the CRCW-PRAM model) can solve the problem in O(n/log n) time with n 1+ε processors. [22] Randomized algorithms can solve the problem in O((log n) 2 ) time on exp ⁡ ( O ( n log ⁡ n ) ) > ight) ight)> processors [ clarification needed ] (this is superpolynomial). [23]

  • Every common divisor of a and b is a divisor of gcd(a, b) .
  • gcd(a, b) , 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 = ap + bq , where p and q are integers. This expression is called Bézout's identity. Numbers p and q like this can be computed with the extended Euclidean algorithm.
  • gcd(a, 0) = | a | , for a ≠ 0 , since any number is a divisor of 0, and the greatest divisor of a is | a |. [3][6] This is usually used as the base case in the Euclidean algorithm.
  • If a divides the product bc, and gcd(a, b) = d , then a/d divides c.
  • If m is a non-negative integer, then gcd(ma, mb) = m⋅gcd(a, b) .
  • If m is any integer, then gcd(a + mb, b) = gcd(a, b) .
  • If m is a positive common divisor of a and b, then gcd(a/m, b/m) = gcd(a, b)/m .
  • The GCD is a multiplicative function in the following sense: if a1 and a2 are relatively prime, then gcd(a1a2, b) = gcd(a1, b)⋅gcd(a2, b) . In particular, recalling that GCD is a positive integer valued function we obtain that gcd(a, bc) = 1 if and only if gcd(a, b) = 1 and gcd(a, c) = 1 .
  • The GCD is a commutative function: gcd(a, b) = gcd(b, a) .
  • The GCD is an associative function: gcd(a, gcd(b, c)) = gcd(gcd(a, b), c) . Thus gcd(a, b, c, . ) can be used to denote the GCD of multiple arguments.
  • gcd(a, b) is closely related to the least common multiple lcm(a, b) : we have gcd(a, b)⋅lcm(a, b) = | ab | .
  • The following versions of distributivity hold true: gcd(a, lcm(b, c)) = lcm(gcd(a, b), gcd(a, c)) lcm(a, gcd(b, c)) = gcd(lcm(a, b), lcm(a, c)) .
  • If we have the unique prime factorizations of a = p1e1p2e2 ⋅⋅⋅ pmem and b = p1f1p2f2 ⋅⋅⋅ pmfm where ei ≥ 0 and fi ≥ 0 , then the GCD of a and b is gcd(a,b) = p1 min(e1,f1) p2 min(e2,f2) ⋅⋅⋅ pm min(em,fm) .
  • It is sometimes useful to define gcd(0, 0) = 0 and lcm(0, 0) = 0 because then the natural numbers become a completedistributive lattice with GCD as meet and LCM as join operation. [24] This extension of the definition is also compatible with the generalization for commutative rings given below.
  • In a Cartesian coordinate system, gcd(a, b) can be interpreted as the number of segments between points with integral coordinates on the straight line segment joining the points (0, 0) and (a, b) .
  • For non-negative integers a and b, where a and b are not both zero, provable by considering the Euclidean algorithm in base n: [25] gcd(na − 1, nb − 1) = n gcd(a,b) − 1 .
  • An identity involving Euler's totient function: gcd ( a , b ) = ∑ k | a and k | b φ ( k ) . >k|b>varphi (k).>

In 1972, James E. Nymann showed that k integers, chosen independently and uniformly from <1, . n>, are coprime with probability 1/ζ(k) as n goes to infinity, where ζ refers to the Riemann zeta function. [26] (See coprime for a derivation.) This result was extended in 1987 to show that the probability that k random integers have greatest common divisor d is d −k /ζ(k). [27]

Using this information, the expected value of the greatest common divisor function can be seen (informally) to not exist when k = 2. In this case the probability that the GCD equals d is d −2 /ζ(2), and since ζ(2) = π 2 /6 we have

This last summation is the harmonic series, which diverges. However, when k ≥ 3, the expected value is well-defined, and by the above argument, it is

For k = 3, this is approximately equal to 1.3684. For k = 4, it is approximately 1.1106.

The notion of greatest common divisor can more generally be defined for elements of an arbitrary commutative ring, although in general there need not exist one for every pair of elements.

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.

With this definition, two elements a and b may very well have several greatest common divisors, or none at all. If R is an integral domain then any two GCD's of a and b must be associate elements, since by definition either one must divide the other indeed if a GCD exists, any one of its associates is a GCD as well. Existence of a GCD is not assured in arbitrary integral domains. However, if R is a unique factorization domain, then any two elements have a GCD, and more generally this is true in GCD domains. If R is a Euclidean domain in which euclidean division is given algorithmically (as is the case for instance when R = F[X] where F is a field, or when R is the ring of Gaussian integers), then greatest common divisors can be computed using a form of the Euclidean algorithm based on the division procedure.

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

The elements 2 and 1 + √ −3 are two maximal common divisors (that is, any common divisor which is a multiple of 2 is associated to 2, the same holds for 1 + √ −3 , but they are not associated, so there is no greatest common divisor of a and b.

Corresponding to the Bézout property we may, in any commutative ring, consider the collection of elements of the form pa + qb, where p and q range over the ring. This is the ideal generated by a and b , and is denoted simply (a, b). In a ring all of whose ideals are principal (a principal ideal domain 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 (a, b) can be useful even when there is no greatest common divisor of a and b. (Indeed, Ernst Kummer used this ideal as a replacement for a GCD in his treatment of Fermat's Last Theorem, although he envisioned it as the set of multiples of some hypothetical, or ideal, ring element d , whence the ring-theoretic term.)


Watch the video: Greatest Common Factor (August 2022).