SlideShare une entreprise Scribd logo
1  sur  20
Euclidean Algorithm
How to find a greatest common
divisor in several easy steps
Euclidean Algorithm
The well known Euclidean algorithm
finds the greatest common divisor of
two numbers using only elementary
mathematical operations - division
and subtraction
Euclidean Algorithm
A divisor of a number a is an integer
that divides it without remainder
For example the divisors of 12 are 1,
2, 3, 4, 6 and 12
The divisors of 18 are 1, 2, 3, 6, 9
and 18.
Euclidean Algorithm
The greatest common divisor, or
GCD, of two numbers is the largest
divisor that is common to both of
them.
For example GCD(12, 18) is the
largest of the divisors common to
both 12 and 18.
Euclidean Algorithm
The common divisors of 12 and 18
are 1, 2, 3 and 6.
Hence GCD(12, 18)=6.
Euclidean Algorithm
The Euclidean Algorithm to find
GCD(a, b) relies upon replacing one
of a or b with the remainder after
division.
Thus the numbers we seek the GCD
of are steadily becoming smaller and
smaller. We stop when one of them
becomes 0.
Euclidean Algorithm
Specifically, we assume that a is
larger than b. If b is larger than a,
then we swap them around so that a
becomes the old b and b becomes the
old a.
We then look for numbers q and r so
that a=bq+r. They must have the
properties that q0 and 0r<b.
In other words, we seek the largest
such q.
Euclidean Algorithm
As examples, consider the following.
a=12, b=5; 12=5*2+2 so q=2, r=2
a=24, b=18; 24=18*1+6 so q=1, r=6
a=30, b=15; 30=15*2+0 so q=2, r=0
a=27, b=14; 27=14*1+13 so q=1,
r=13
Try the ones on the next slide.
Euclidean Algorithm
Find q and r for the following sets of
a and b. The answers are on the next
slide.
a=28, b=12
a=50, b=30
a=35, b=14
a=100, b=20
Euclidean Algorithm
Answers
q=2, r=4
q=1, r=20
q=2, r=7
q=5, r=0
Euclidean Algorithm
The algorithm works in the
following way.
Given a and b, we find numbers q
and r so that a=bq+r.
We make sure that q is as large as
possible (≥0), and 0≤r<b.
For example, if a=18, b=12, then
we write 18=12*1+6.
Euclidean Algorithm
Actually the number q isn’t important,
it is just easier to find r with it when
solving problems by hand. Most
software can find the remainder r
without finding q.
For example the Java statement below
will find r.
r=a%b;
Euclidean Algorithm
Once the remainder r has been found
we replace a by b and b by r.
This relies on the fact that
GCD(a,b)=GCD(b,r).
Hence we repeatedly find r, the
remainder after a is divided by b.
Then replace a by b and b by r, and
keep on in this way until r=0.
Euclidean Algorithm
Let us look at a graphical interpretation
of the Euclidean algorithm.
Obviously if p=GCD(a,b) then p|a and
p|b, that is to say p divides both a and b
evenly with no remainder.
Euclidean Algorithm
Suppose a and b are represented by
the lengths below.
Euclidean Algorithm
Note that b does not go into a evenly, but
has some small remainder.
Euclidean Algorithm
If p is the GCD of a and b then it divides
evenly into both a and b. Hence it divides
evenly into b and thus must divide evenly
into both of the larger two boxes in the
previous diagram.
Euclidean Algorithm
Then p divides the length representing b a
whole number of times, and hence the boxes
in a that represent whole lengths of b.
Euclidean Algorithm
Of course if p divides a evenly then it must
also divide the remainder evenly. The
picture below shows this.
Euclidean Algorithm
Hopefully it will be clear that by now
any number that divides both a and b
must also divide the remainder r.
The largest of these will of course be
the GCD of a and b.
So GCD(a,b)=GCD(b,r).

Contenu connexe

Tendances

Interesting applications of graph theory
Interesting applications of graph theoryInteresting applications of graph theory
Interesting applications of graph theory
Tech_MX
 
Math Quiz Final round with answer
Math Quiz Final round with answerMath Quiz Final round with answer
Math Quiz Final round with answer
Emam Khan
 
Lesson 5: Matrix Algebra (slides)
Lesson 5: Matrix Algebra (slides)Lesson 5: Matrix Algebra (slides)
Lesson 5: Matrix Algebra (slides)
Matthew Leingang
 
mathematical induction
mathematical inductionmathematical induction
mathematical induction
ankush_kumar
 

Tendances (20)

Discrete Math Ch5 counting + proofs
Discrete Math Ch5 counting + proofsDiscrete Math Ch5 counting + proofs
Discrete Math Ch5 counting + proofs
 
Clocks
ClocksClocks
Clocks
 
Shortest Path Problem
Shortest Path ProblemShortest Path Problem
Shortest Path Problem
 
Interesting applications of graph theory
Interesting applications of graph theoryInteresting applications of graph theory
Interesting applications of graph theory
 
Fibonacci numbers And Lucas numbers
Fibonacci numbers And  Lucas numbersFibonacci numbers And  Lucas numbers
Fibonacci numbers And Lucas numbers
 
Discrete maths questions
Discrete maths questionsDiscrete maths questions
Discrete maths questions
 
Math Quiz Final round with answer
Math Quiz Final round with answerMath Quiz Final round with answer
Math Quiz Final round with answer
 
Spectral factorization
Spectral factorizationSpectral factorization
Spectral factorization
 
Eucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomialsEucledian algorithm for gcd of integers and polynomials
Eucledian algorithm for gcd of integers and polynomials
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
G. ripple counter
G. ripple counterG. ripple counter
G. ripple counter
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
 
Find transitive-closure using warshalls-algorithm
Find transitive-closure  using warshalls-algorithmFind transitive-closure  using warshalls-algorithm
Find transitive-closure using warshalls-algorithm
 
Cryptography - Discrete Mathematics
Cryptography - Discrete MathematicsCryptography - Discrete Mathematics
Cryptography - Discrete Mathematics
 
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptfdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
 
Mathematics high school level quiz - Part I
Mathematics high school level quiz - Part IMathematics high school level quiz - Part I
Mathematics high school level quiz - Part I
 
Real Numbers - Proofs based on irrational numbers for Class 10th maths.
Real Numbers - Proofs based on irrational numbers for Class 10th maths.Real Numbers - Proofs based on irrational numbers for Class 10th maths.
Real Numbers - Proofs based on irrational numbers for Class 10th maths.
 
Lesson 5: Matrix Algebra (slides)
Lesson 5: Matrix Algebra (slides)Lesson 5: Matrix Algebra (slides)
Lesson 5: Matrix Algebra (slides)
 
mathematical induction
mathematical inductionmathematical induction
mathematical induction
 
Discrete Mathematics Presentation
Discrete Mathematics PresentationDiscrete Mathematics Presentation
Discrete Mathematics Presentation
 

Similaire à GCD.ppt

Problems and solutions, inmo 2011
Problems and solutions, inmo 2011Problems and solutions, inmo 2011
Problems and solutions, inmo 2011
askiitians
 
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docx
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docxSection 0.7 Quadratic Equations from Precalculus Prerequisite.docx
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docx
bagotjesusa
 

Similaire à GCD.ppt (20)

DIVISIBILITY PDF.pdf
DIVISIBILITY PDF.pdfDIVISIBILITY PDF.pdf
DIVISIBILITY PDF.pdf
 
Lec_2.pdf
Lec_2.pdfLec_2.pdf
Lec_2.pdf
 
Problems and solutions, inmo 2011
Problems and solutions, inmo 2011Problems and solutions, inmo 2011
Problems and solutions, inmo 2011
 
Chapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdfChapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdf
 
Real number by G R Ahmed of KVK
Real number by G R Ahmed of KVKReal number by G R Ahmed of KVK
Real number by G R Ahmed of KVK
 
NumberTheory.ppt
NumberTheory.pptNumberTheory.ppt
NumberTheory.ppt
 
Real numbers
Real numbers Real numbers
Real numbers
 
Abstract Algebra Beamer Lesson1
Abstract Algebra Beamer Lesson1Abstract Algebra Beamer Lesson1
Abstract Algebra Beamer Lesson1
 
Chapter1.integer s.y.b.c.s
Chapter1.integer s.y.b.c.sChapter1.integer s.y.b.c.s
Chapter1.integer s.y.b.c.s
 
CRYPTO 2.pptx
CRYPTO 2.pptxCRYPTO 2.pptx
CRYPTO 2.pptx
 
Lecture-1.pptx
Lecture-1.pptxLecture-1.pptx
Lecture-1.pptx
 
555_Spring12_topic06.ppt
555_Spring12_topic06.ppt555_Spring12_topic06.ppt
555_Spring12_topic06.ppt
 
GCD of n Numbers
GCD of n NumbersGCD of n Numbers
GCD of n Numbers
 
Complete ncert exemplar class 10
Complete ncert exemplar class 10Complete ncert exemplar class 10
Complete ncert exemplar class 10
 
X ch 1 real numbers
X  ch 1  real numbersX  ch 1  real numbers
X ch 1 real numbers
 
Ncert Maths Class-X | Chapter-1 | Slides By MANAV |
Ncert Maths Class-X | Chapter-1 | Slides By MANAV |Ncert Maths Class-X | Chapter-1 | Slides By MANAV |
Ncert Maths Class-X | Chapter-1 | Slides By MANAV |
 
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docx
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docxSection 0.7 Quadratic Equations from Precalculus Prerequisite.docx
Section 0.7 Quadratic Equations from Precalculus Prerequisite.docx
 
integrated algebra.pptx
integrated algebra.pptxintegrated algebra.pptx
integrated algebra.pptx
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Module 1 similarity
Module 1 similarityModule 1 similarity
Module 1 similarity
 

Dernier

Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
chadhar227
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
nirzagarg
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
wsppdmt
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
vexqp
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
nirzagarg
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
ranjankumarbehera14
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdf
SayantanBiswas37
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
HyderabadDolls
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
Health
 

Dernier (20)

Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdf
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 

GCD.ppt

  • 1. Euclidean Algorithm How to find a greatest common divisor in several easy steps
  • 2. Euclidean Algorithm The well known Euclidean algorithm finds the greatest common divisor of two numbers using only elementary mathematical operations - division and subtraction
  • 3. Euclidean Algorithm A divisor of a number a is an integer that divides it without remainder For example the divisors of 12 are 1, 2, 3, 4, 6 and 12 The divisors of 18 are 1, 2, 3, 6, 9 and 18.
  • 4. Euclidean Algorithm The greatest common divisor, or GCD, of two numbers is the largest divisor that is common to both of them. For example GCD(12, 18) is the largest of the divisors common to both 12 and 18.
  • 5. Euclidean Algorithm The common divisors of 12 and 18 are 1, 2, 3 and 6. Hence GCD(12, 18)=6.
  • 6. Euclidean Algorithm The Euclidean Algorithm to find GCD(a, b) relies upon replacing one of a or b with the remainder after division. Thus the numbers we seek the GCD of are steadily becoming smaller and smaller. We stop when one of them becomes 0.
  • 7. Euclidean Algorithm Specifically, we assume that a is larger than b. If b is larger than a, then we swap them around so that a becomes the old b and b becomes the old a. We then look for numbers q and r so that a=bq+r. They must have the properties that q0 and 0r<b. In other words, we seek the largest such q.
  • 8. Euclidean Algorithm As examples, consider the following. a=12, b=5; 12=5*2+2 so q=2, r=2 a=24, b=18; 24=18*1+6 so q=1, r=6 a=30, b=15; 30=15*2+0 so q=2, r=0 a=27, b=14; 27=14*1+13 so q=1, r=13 Try the ones on the next slide.
  • 9. Euclidean Algorithm Find q and r for the following sets of a and b. The answers are on the next slide. a=28, b=12 a=50, b=30 a=35, b=14 a=100, b=20
  • 11. Euclidean Algorithm The algorithm works in the following way. Given a and b, we find numbers q and r so that a=bq+r. We make sure that q is as large as possible (≥0), and 0≤r<b. For example, if a=18, b=12, then we write 18=12*1+6.
  • 12. Euclidean Algorithm Actually the number q isn’t important, it is just easier to find r with it when solving problems by hand. Most software can find the remainder r without finding q. For example the Java statement below will find r. r=a%b;
  • 13. Euclidean Algorithm Once the remainder r has been found we replace a by b and b by r. This relies on the fact that GCD(a,b)=GCD(b,r). Hence we repeatedly find r, the remainder after a is divided by b. Then replace a by b and b by r, and keep on in this way until r=0.
  • 14. Euclidean Algorithm Let us look at a graphical interpretation of the Euclidean algorithm. Obviously if p=GCD(a,b) then p|a and p|b, that is to say p divides both a and b evenly with no remainder.
  • 15. Euclidean Algorithm Suppose a and b are represented by the lengths below.
  • 16. Euclidean Algorithm Note that b does not go into a evenly, but has some small remainder.
  • 17. Euclidean Algorithm If p is the GCD of a and b then it divides evenly into both a and b. Hence it divides evenly into b and thus must divide evenly into both of the larger two boxes in the previous diagram.
  • 18. Euclidean Algorithm Then p divides the length representing b a whole number of times, and hence the boxes in a that represent whole lengths of b.
  • 19. Euclidean Algorithm Of course if p divides a evenly then it must also divide the remainder evenly. The picture below shows this.
  • 20. Euclidean Algorithm Hopefully it will be clear that by now any number that divides both a and b must also divide the remainder r. The largest of these will of course be the GCD of a and b. So GCD(a,b)=GCD(b,r).