Euclid's Division Algorithm
Last Updated : 28 Nov, 2024
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 theory and helps in simplifying problems involving divisors and multiples.
According to the Euclidean Division Algorithm two positive integers a and b, where a = bq + r, a common divisor of a and b is also a common divisor of b and r, and vice versa, GCD(a, b) = GCD(b, r).
Steps to find the GCD(A, B) using the Euclidean Division Algorithm:
- Express A in quotient-remainder form:
- A = B ⋅ Q + R, where Q is the quotient and R is the remainder.
- Apply the Euclidean Algorithm to find GCD(B, R), since GCD(A, B) = GCD(B, R).
- Repeat the process until the remainder becomes zero. as, GCD(0, X) = X.
- If A = 0, then GCD(A, B) = B, because GCD(0, B) = B. In this case, the process stops.
- If B = 0, then GCD(A, B) = A, because GCD(A, 0) = A. In this case, the process stops.
Proof Of Euclidean Division Algorithm
To Prove: For a = bq + r, any common divisor of a and b is also a common divisor of b and r, and vice versa.
Proof: Let c be a common divisor of a and b. This means:
- c divides a, so a = cq1 for some integer q1.
- c divides b, so b = cq2 for some integer q2.
Now, using the relation a = bq + r, we can write: r = a − bq.
Substitute a = cq1 and b = cq2: r = cq1 − cq2q.
Factor out c: r = c(q1 − q2q)...............(i)
This shows that c∣r. Hence, c divides both b and r, meaning c is a common divisor of b and r.
Thus, any common divisor of a and b is also a common divisor of b and r.
Now, let d be a common divisor of b and r. This means:
- d divides b, so b = r1d for some integer r1.
- d divides r, so r = r2d for some integer r2.
Using the relation a = bq + r , substitute b = r1d and r = r2d: a = r1dq + r2d.
Factor out d: a = d(r1q + r2)...............(ii)
This shows that d divides a. Thus, d divides both a and b, meaning d is a common divisor of a and b.
From the two parts above (i) and (ii), we conclude that:
GCD(a, b) = GCD(b, r)
The Euclidean Algorithm repeatedly applies the division a = bq + r by replacing (a, b) with (b, r). At each step, the remainder r strictly decreases because 0 ≤ r < b0.
Since r is a non-negative integer, the sequence of remainders: a, b, r1, r2, … , a > b > r1 > r2 > …, must eventually reach r = 0 after a finite number of steps.
When the algorithm terminates(r = 0), the last non-zero value of b is the greatest common divisor (GCD) of the original integers a and b.
Thus, the Euclidean Division Algorithm is both valid and guaranteed to terminate in a finite number of steps, providing the greatest common divisor (GCD) of the original integers a and b.
GCD of Two Numbers Using Euclid’s Division Algorithm
The GCD of two numbers can be found by using the Euclidean division algorithm as shown in the steps below.
Given two integers a (dividend) and b (divisor), where a ≥ b > 0,
Step 1: Divide a by b to get a quotient q and a remainder r:
a = b ⋅ q + r where 0 ≤ r < b.
Step 2: Replace a with b and b with r.
Step 3: Repeat the process until r = 0.
Step 4: When you get a remainder of zero, the last non-zero remainder you found is the greatest common divisor (GCD) of the original two numbers as GCD( 0, A ) = GCD( A, 0 ) = A
Example 1: Find the GCD of 252 and 105
Solution:
Divide 252 by 105:
252 = 105 × 2 + 42 ( Quotient = 2, Remainder = 42)
Replace a with 105 and b with 42, then divide again, since GCD(252, 105) = GCD(105, 42):
105 = 42 × 2 + 21 ( Quotient = 2, Remainder = 21)
Replace a with 42 and b with 21, then divide again, since GCD(105, 42) = GCD(42, 21):
42 = 21 × 2 + 0 ( Quotient = 2, Remainder = 0)
Stop here because the remainder is now 0 and GCD(42, 21) = GCD(21, 0).
And GCD(21, 0) = 21
then, GCD(252, 105) = GCD(105, 42) = GCD(42, 21) = GCD(21, 0) = 21
GCD(252, 105) = 21.
Example 2: Find the GCD of 360 and 96
Solution:
Divide 360 by 96:
360 = 96 × 3 + 72 (Quotient = 3, Remainder = 72)
Replace a with 96 and b with 72, then divide again, since GCD(360, 96) = GCD(96, 72):
96 = 72 × 1 + 24 (Quotient = 1, Remainder = 24)
Replace a with 72 and b with 24, then divide again, since GCD(96, 72) = GCD(72, 24):
72 = 24 × 3 + 0 (Quotient = 3, Remainder = 0)
Stop here because the remainder is now 0 and GCD(72, 24) = GCD(24, 0).
And GCD(24, 0) = 24
then, GCD(360, 96) = GCD(96, 72) = GCD(72, 24) = GCD(24, 0) = 24
GCD(360, 96) = 24
Next Article - Extended Euclidean Algorithm
For Programmers –
Similar Reads
Extended Euclid Division Algorithm 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
7 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
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
Euclid 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
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: 4Explanatio
9 min read