Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Number System and Arithmetic
  • Algebra
  • Set Theory
  • Probability
  • Statistics
  • Geometry
  • Calculus
  • Logarithms
  • Mensuration
  • Matrices
  • Trigonometry
  • Mathematics
Open In App
Next Article:
Euclid's Division Algorithm
Next article icon

Euclid's Division Algorithm

Last Updated : 28 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 –

  • Euclidean Algorithm's basic and extended

Next Article
Euclid's Division Algorithm

S

surajb1g23
Improve
Article Tags :
  • Mathematics
  • School Learning
  • GCD-LCM
  • Maths

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences