From Wikimedia Commons, the free media repository. File information. Structured data. Captions English Add a one-line explanation of what this file represents.
|Published (Last):||24 June 2018|
|PDF File Size:||20.44 Mb|
|ePub File Size:||9.56 Mb|
|Price:||Free* [*Free Regsitration Required]|
In mathematics , the Euclidean algorithm , [note 1] or Euclid's algorithm , is an efficient method for computing the greatest common divisor GCD of two integers numbers , the largest number that divides them both without a remainder. It is named after the ancient Greek mathematician Euclid , who first described it in his Elements c.
It is an example of an algorithm , a step-by-step procedure for performing a calculation according to well-defined rules, and is one of the oldest algorithms in common use. It can be used to reduce fractions to their simplest form , and is a part of many other number-theoretic and cryptographic calculations.
The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until the two numbers become equal. When that occurs, they are the GCD of the original two numbers.
By reversing the steps , the GCD can be expressed as a sum of the two original numbers each multiplied by a positive or negative integer , e. The version of the Euclidean algorithm described above and by Euclid can take many subtraction steps to find the GCD when one of the given numbers is much bigger than the other. A more efficient version of the algorithm shortcuts these steps, instead replacing the larger of the two numbers by its remainder when divided by the smaller of the two with this version, the algorithm stops when reaching a zero remainder.
With this improvement, the algorithm never requires more steps than five times the number of digits base 10 of the smaller integer. Additional methods for improving the algorithm's efficiency were developed in the 20th century. The Euclidean algorithm has many theoretical and practical applications.
It is used for reducing fractions to their simplest form and for performing division in modular arithmetic. Computations using this algorithm form part of the cryptographic protocols that are used to secure internet communications, and in methods for breaking these cryptosystems by factoring large composite numbers.
The Euclidean algorithm may be used to solve Diophantine equations , such as finding numbers that satisfy multiple congruences according to the Chinese remainder theorem , to construct continued fractions , and to find accurate rational approximations to real numbers. Finally, it can be used as a basic tool for proving theorems in number theory such as Lagrange's four-square theorem and the uniqueness of prime factorizations.
The original algorithm was described only for natural numbers and geometric lengths real numbers , but the algorithm was generalized in the 19th century to other types of numbers, such as Gaussian integers and polynomials of one variable.
This led to modern abstract algebraic notions such as Euclidean domains. The Euclidean algorithm calculates the greatest common divisor GCD of two natural numbers a and b. The greatest common divisor g is the largest natural number that divides both a and b without leaving a remainder. Nevertheless, 6 and 35 are coprime. No natural number other than 1 divides both 6 and 35, since they have no prime factors in common.
The natural numbers m and n must be coprime, since any common factor could be factored out of m and n to make g greater.
Thus, any other number c that divides both a and b must also divide g. The greatest common divisor g of a and b is the unique positive common divisor of a and b that is divisible by any other common divisor c. The GCD can be visualized as follows. The sides of the rectangle can be divided into segments of length c , which divides the rectangle into a grid of squares of side length c. The greatest common divisor g is the largest value of c for which this is possible. For illustration, a by 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 by squares.
Therefore, 12 is the greatest common divisor of 24 and The GCD of two numbers a and b is the product of the prime factors shared by the two numbers, where a same prime factor can be used multiple times, but only as long as the product of these factors divides both a and b.
If two numbers have no prime factors in common, their greatest common divisor is 1 obtained here as an instance of the empty product , in other words they are coprime. A key advantage of the Euclidean algorithm is that it can find the GCD efficiently without having to compute the prime factors. Another definition of the GCD is helpful in advanced mathematics, particularly ring theory. The set of all integral linear combinations of a and b is actually the same as the set of all multiples of g mg , where m is an integer.
The equivalence of this GCD definition with the other definitions is described below. The GCD of three or more numbers equals the product of the prime factors common to all the numbers,  but it can also be calculated by repeatedly taking the GCDs of pairs of numbers.
The Euclidean algorithm proceeds in a series of steps such that the output of each step is used as an input for the next one. Let k be an integer that counts the steps of the algorithm, starting with zero. The goal of the k th step is to find a quotient q k and remainder r k that satisfy the equation.
Thus, the algorithm can be written as a sequence of equations. If a is smaller than b , the first step of the algorithm swaps the numbers.
Since the remainders decrease with every step but can never be negative, a remainder r N must eventually equal zero, at which point the algorithm stops. The number N cannot be infinite because there are only a finite number of nonnegative integers between the initial remainder r 0 and zero. The validity of the Euclidean algorithm can be proven by a two-step argument.
Since it is a common divisor, it must be less than or equal to the greatest common divisor g. In the second step, any natural number c that divides both a and b in other words, any common divisor of a and b divides the remainders r k.
An analogous argument shows that c also divides the subsequent remainders r 1 , r 2 , etc. Thus, g is the greatest common divisor of all the succeeding pairs:  . To begin, multiples of are subtracted from until the remainder is less than Then multiples of are subtracted from until the remainder is less than Then multiples of 21 are subtracted from until the remainder is less than Since the last remainder is zero, the algorithm ends with 21 as the greatest common divisor of and This agrees with the gcd , found by prime factorization above.
In tabular form, the steps are:. The Euclidean algorithm can be visualized in terms of the tiling analogy given above for the greatest common divisor. We then attempt to tile the residual rectangle with r 0 -by- r 0 square tiles. This leaves a second residual rectangle r 1 -by- r 0 , which we attempt to tile using r 1 -by- r 1 square tiles, and so on.
The sequence ends when there is no residual rectangle, i. The length of the sides of the smallest square tile is the GCD of the dimensions of the original rectangle. For example, the smallest square tile in the adjacent figure is by shown in red , and 21 is the GCD of and , the dimensions of the original rectangle shown in green. The theorem which underlies the definition of the Euclidean division ensures that such a quotient and remainder always exist and are unique.
Euclidean division reduces all the steps between two exchanges into a single step, which is thus more efficient. Moreover, the quotients are not needed, thus one may replace Euclidean division by the modulo operation , which gives only the remainder. Thus the iteration of the Euclidean algorithm becomes simply. Implementations of the algorithm may be expressed in pseudocode. For example, the division-based version may be programmed as .
During the loop iteration, a is reduced by multiples of the previous remainder b until a is smaller than b. Then a is the next remainder r k. In another version of Euclid's algorithm, the quotient at each step is increased by one if the resulting negative remainder is smaller in magnitude than the typical positive remainder.
However, an alternative negative remainder e k can be computed:. If r k is replaced by e k. Leopold Kronecker has shown that this version requires the least number of steps of any version of Euclid's algorithm. The Euclidean algorithm is one of the oldest algorithms in common use. In modern usage, one would say it was formulated there for real numbers.
But lengths, areas, and volumes, represented as real numbers in modern usage, are not measured in the same units and there is no natural unit of length, area, or volume; the concept of real numbers was unknown at that time.
The latter algorithm is geometrical. The GCD of two lengths a and b corresponds to the greatest length g that measures a and b evenly; in other words, the lengths a and b are both integer multiples of the length g.
The algorithm was probably not discovered by Euclid , who compiled results from earlier mathematicians in his Elements. Centuries later, Euclid's algorithm was discovered independently both in India and in China,  primarily to solve Diophantine equations that arose in astronomy and making accurate calendars. In the late 5th century, the Indian mathematician and astronomer Aryabhata described the algorithm as the "pulverizer",  perhaps because of its effectiveness in solving Diophantine equations.
The extended Euclidean algorithm was published by the English mathematician Nicholas Saunderson ,  who attributed it to Roger Cotes as a method for computing continued fractions efficiently. In the 19th century, the Euclidean algorithm led to the development of new number systems, such as Gaussian integers and Eisenstein integers.
In , Carl Gauss used the Euclidean algorithm to demonstrate unique factorization of Gaussian integers , although his work was first published in For example, Dedekind was the first to prove Fermat's two-square theorem using the unique factorization of Gaussian integers.
In the closing decades of the 19th century, the Euclidean algorithm gradually became eclipsed by Dedekind's more general theory of ideals.
Other applications of Euclid's algorithm were developed in the 19th century. In , Charles Sturm showed that the algorithm was useful in the Sturm chain method for counting the real roots of polynomials in any given interval. The Euclidean algorithm was the first integer relation algorithm , which is a method for finding integer relations between commensurate real numbers.
Several novel integer relation algorithms have been developed, such as the algorithm of Helaman Ferguson and R. Forcade  and the LLL algorithm. In , Cole and Davie developed a two-player game based on the Euclidean algorithm, called The Game of Euclid ,  which has an optimal strategy. The players take turns removing m multiples of the smaller pile from the larger.
The winner is the first player to reduce one pile to zero stones. The integers s and t can be calculated from the quotients q 0 , q 1 , etc. Those two remainders can be likewise expressed in terms of their quotients and preceding remainders,. The process of substituting remainders by formulae involving their predecessors can be continued until the original numbers a and b are reached:.
After all the remainders r 0 , r 1 , etc.
Euclidean algorithms (Basic and Extended)
GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and multiply common factors. Extended Euclidean Algorithm: Extended Euclidean algorithm also finds integer coefficients x and y such that:. Let values of x and y calculated by the recursive call be x 1 and y 1. How is Extended Algorithm Useful? The extended Euclidean algorithm is particularly useful when a and b are coprime or gcd is 1.
Euclid's Algorithm Calculator
File:Euclid flowchart 1.png