Extended Euclid Division Algorithm
Last Updated :
28 Nov, 2024
The Extended Euclidean Algorithm is an extension of the classic Euclidean Algorithm. While the Euclidean Algorithm focuses on finding the greatest common divisor (GCD) of two integers, the Extended Euclidean Algorithm can also find integers x and y to express their greatest common divisor (gcd) as a linear combination of numbers.
Extended Euclidean Algorithm, states that
For any two integers a and b (with b≠0 ), it is possible to express their greatest common divisor (GCD) as a linear combination of a and b. Specifically, if d=GCD(a, b) then there exist unique integers x and y such that
d = ax + by
Where d is the greatest divisor of a and b i.e. d= GCD(a, b)
This expression of greatest common divisor (GCD) as a linear combination of a and b is called the Bezout Identity.
Proof of Extended Euclidean Algorithm
The proof of the Extended Euclidean Algorithm involves demonstrating two main aspects:
- Finding the GCD: Show that the algorithm indeed finds the greatest common divisor (GCD) of two integers a and b.
- Linear Combination: Prove that it expresses the GCD as a linear combination of a and b.
Follow these steps to understand the proof of the Extended Euclidean Algorithm, which calculates the GCD of two integers a and b and expresses it as a linear combination.
Step 1: Euclidean Algorithm Setup.
First, write the Euclidean Algorithm as a series of steps finding remainders:
- a = bq1 + r1 (where r1 is the remainder when a is divided by b.)
- b = r1 q2 + r2
- r1 = r2 q3 + r3
- Continue until rn − 1 = rnqn + 1 + 0
Here, GCD(a ,b) = rn, the last non-zero remainder.
Step 2: Expressing the GCD as a Linear Combination.
This critical step where we will express each remainder ri as a linear combination of a and b.
- Starting with the final remainder equation that equals the GCD.
- rn = rn − 2 − rn − 1 qn
Here, qn is the quotient from the previous division.
We will continue this process backtracking through all previous equations, substituting for each each ri until we can express rn (which is GCD(a, b)) purely in terms of a and b.
For example, if we had the sequence:
- rn − 1 = rn − 3 − rn − 2qn − 1
Substituting this into the equation for rn:
- rn = (rn − 3 − rn − 2qn − 1) − rn − 1qn
Continue this process until all ri are expressed in terms of a and b.
Step 3: Recursive Construction of Coefficients.
To keep track of the coefficients x and y in the equation ax + by = GCD(a, b), we define:
- x0 = 1, y0 = 0 (for a)
- x1 = 0, y1 = 1 (for b)
For each step i, as we perform divisions, we also compute:
For each remainder equation:
The coefficients x and y for the new remainder can be calculated as follows:
From
- ri = ri − 2 − ri − 1qi:
- xi = xi − 2 − xi − 1qi
- yi = yi − 2 − yi − 1qi
This process allows for the recursive construction of the coefficients x and y for each step.
Step 4: Final Expression for GCD(a, b).
After back-substituting through the remainder equations, you will eventually reach a point where:
where rn = GCD(a, b). The integers x and y are the coefficients we sought.
This concludes the proof of the Extended Euclidean Algorithm, illustrating how to find x and y such that ax + by = GCD(a, b).
Lets understand the Extended Euclid Division Algorithm with an example,
Example 1: Find two integers a and b such that 240a + 46b = GCD(240, 46).
Solution:
First we use Euclid's algorithm to find the GCD( 240, 46);
240 = 46 × 5 + 1 0 .... (i)
46 = 10 × 4 + 6 .... (ii)
10 = 6 × 1 + 4 .... (iii)
6 = 4 × 1 + 2 .... (iv)
4 = 2 × 2 + 0 .... (v)
So GCD( 240, 46) is 2
Now we rewrite the remainder equation to express the GCD as a combination of 240 and 46.
from eq (iv) we get
2 = 6 - 4 × 1
From eq(iii) we get , ( 4 = 10 - 6) substituting this value in the above equation
2 = 6 - ( 10 -6) × 1
2 = 6 × 2 - 10
From eq(ii) we get, ( 6 = 46 -10 × 4) substituting this value in the above equation
2 = (46 − 10 × 4 ) × 2 − 10 = 46 × 2 − 10 × 9
2 = 46 × 2 − 10 × 9
From eq(i) we get, ( 10 = 240 − 46 × 5) substituting this value in the above equation
2 = 46 × 2 − ( 240 − 46 × 5 ) × 9 = 46 × 2 − ( 240 × 9 − 46 × 45) = 46 × 47 - 240 × 9
2 = 46 × 47 - 240 × 9
So, x = − 9 and y = 47,
which satisfies the equation ax + by = GCD ( a, b )
240( − 9) + 46(47) = 2
Example 2: Solve the linear equation 81x + 57y=3 to finding values of x and y using the Extended Euclidean Algorithm.
Solution:
First we use Euclid's algorithm to find the GCD( 81, 57);
81 = 57 × 1 + 24 .... (i)
57 = 24 × 2 + 9 .... (ii)
24 = 9 × 2 + 6 .... (iii)
9 = 6 × 1 + 3 .... (iv)
6 = 3 × 2 + 0 .... (v)
So GCD( 240, 46) is 3
Now we rewrite the remainder equation to express the GCD as a combination of 81 and 57.
from eq (iv) ( 9 = 6 × 1 + 3 ) we get
3 = 9 - 6 × 1
From eq(iii) we get , ( 6 = 24 - 9 × 2) substituting this value in the above equation
3 = 9 - ( 24 - 9 × 2 ) × 1
3 = 9 × 3 - 24
From eq(ii) we get, ( 9 = 57 -24 × 2) substituting this value in the above equation
3 = (57 -24 × 2) × 3 - 24
3 = 57 × 3 − 24 × 7
From eq(i) we get, ( 24 = 81 - 57 × 1) substituting this value in the above equation
3 = 57 × 3 − (81 - 57 ) × 7 = 57 × 10 − 81 × 7
3 = 57 × 10 + 81 × (-7)
Comparing it with 81x + 57y = 3 we get
So, x = -7 and y = 10,
which satisfies the equation
240( − 9) + 46(47) = 2
ax + by = GCD ( a, b )
Uses of the Extended Euclidean Algorithm
The Extended Euclidean Algorithm is helpful in a few important areas:
- Cryptography: It helps in finding modular inverses, which are necessary for encryption and decryption in RSA and other cryptographic methods.
- Solving Equations: It can solve certain equations that need integer solutions, called linear Diophantine equations, like
( ax + by = c) - Modular Arithmetic: It finds inverses that help in modular arithmetic, allowing operations with fractions in modular systems.
- Computer Algorithms: Many computer programs use the Extended Euclidean Algorithm for mathematical functions, especially when working with large numbers.
Next Article - Applications of GCD in Real Life
For Programmer -
Euclidean Algorithms basic and extended
Similar Reads
Euclid's Division Algorithm
The Euclidean Division Algorithm is a method used in mathematics to find the greatest common divisor (GCD) of two integers. It is based on Euclid's Division Lemma. In this algorithm, we repeatedly divide and find remainders until the remainder becomes zero. This process is fundamental in number theo
6 min read
Euclidean algorithms (Basic and Extended)
The Euclidean algorithm is a way to find the greatest common divisor of two positive integers. 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 prime factors. Examples: input: a = 12, b = 20Output: 4Explanat
9 min read
Common Divisor Reduction Algorithm
Given two integers x and y. In one step, we have to subtract the greatest common divisor of x and y from x and y each till x ⥠1 and y ⥠1. We have to find the minimum number of repetitions of this step. Examples: Input: x = 36, y = 16Output: 4Explanation: GCD of 36 and 16 is 4, so replace 36 and 16
11 min read
Division Algorithm for Polynomials
Polynomials are those algebraic expressions that contain variables, coefficients, and constants. For Instance, in the polynomial 8x2 + 3z - 7, in this polynomial, 8,3 are the coefficients, x and z are the variables, and 7 is the constant. Just as simple Mathematical operations are applied on numbers
5 min read
Division Algorithm Problems and Solutions
Polynomials are made up of algebraic expressions with different degrees. Degree-one polynomials are called linear polynomials, degree-two are called quadratic and degree-three are called cubic polynomials. Zeros of these polynomials are the points where these polynomials become zero. Sometimes it ha
6 min read
Euclid's Division Lemma
Euclid's Division Lemma which is one of the fundamental theorems proposed by the ancient Greek mathematician Euclid which was used to prove various properties of integers. The Euclid's Division Lemma also serves as a base for Euclid's Division Algorithm which is used to find the GCD of any two numbe
5 min read
Greatest Common Divisor - GCD
The Greatest Common Divisor (GCD) also known as the Highest Common Factor (HCF) is the greatest number that divides a set of numbers without leaving a remainder. For example: GCD of 12 and 18 is 6 as it divides both numbers and is the largest of all their factors. The GCD of any two numbers is never
4 min read
Division of a Line Segment Practice Problems
The Division of a Line Segment is one of the basic concepts in geometry that helps to understand different principles. It is the process of determining a point that will split a given line segment into the desired ratio either inside or outside the original line segment. This article consists of sol
8 min read
Long Division Worksheets
Long division is a method used to divide large numbers by breaking them down into simpler steps. It involves dividing the dividend by the divisor, subtracting and then bringing down the next digit to continue until the entire dividend has been divided. Division Formula Dividend = (Divisor à Quotient
2 min read
Reduce the fraction to its lowest form
Given two integers x and y and where x is divisible by y. It can be represented in the form of a fraction x/y. The task is to reduce the fraction to its lowest form.Examples: Input : x = 16, y = 10 Output : x = 8, y = 5 Input : x = 10, y = 8 Output : x = 5, y = 4 Approach: Both of the values x and y
4 min read