The Wayback Machine - https://web.archive.org/web/20250317140806/https://www.geeksforgeeks.org/euclid-s-division-algorithm/
Open In App

Euclid's Division Algorithm

Last Updated : 28 Nov, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

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:

  1. c divides a, so a = cq1 ​ for some integer q1​.
  2. 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 –

Euclid’s Division Algorithm – FAQs

What is Euclid’s Division Algorithm?

Euclid’s Division Algorithm is an algorithm which is used to find the HCF of two numbers by using Euclid’s Division Lemma in succession till the remainder(r) is made zero.

What is the difference between Euclid’s Division Lemma and  Euclid’s Division Algorithm?

Euclid’s Division Lemma is the basic theorem of Euclid’s Division whereas Euclid’s Division Algorithm is an Algorithm which uses Euclid’s Division Lemma to find the HCF of two numbers.

What is the use of Euclid’s Division Algorithm?

Euclid’s Division Algorithm is used to find the HCF of two or more numbers.

How does the Euclid Algorithm calculate HCF?

The HCF of two numbers a and b can be calculated using Euclid Algorithm by following the steps discussed below,

  • Step 1: Use Euclid’s Division Lemma, a and b. So, we find q and r such that a = bq + r, 0 ≤ r < b.
  • Step 2: If r = 0, b is the HCF of a and b. If r ≠ 0, repeat step 1 till the remainder becomes zero.
  • Step 3: In the case when the remainder is zero, the divisor b is the HCF of a and b.

Next Article

Similar Reads

three90RightbarBannerImg