SlideShare uma empresa Scribd logo
1 de 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).

Mais conteúdo relacionado

Mais procurados

Combinatorics.pptx
Combinatorics.pptxCombinatorics.pptx
Combinatorics.pptxHanachiTan
 
Coin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic ProgrammingCoin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic ProgrammingSyeda Khadizatul maria
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence RelationPapu Kumar
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notationsjayavignesh86
 
Generating functions solve recurrence
Generating functions solve recurrenceGenerating functions solve recurrence
Generating functions solve recurrenceHae Morgia
 
Gauss jordan and Guass elimination method
Gauss jordan and Guass elimination methodGauss jordan and Guass elimination method
Gauss jordan and Guass elimination methodMeet Nayak
 
Higher Differential Equation
Higher Differential Equation Higher Differential Equation
Higher Differential Equation Abdul Hannan
 
Methods of solving ODE
Methods of solving ODEMethods of solving ODE
Methods of solving ODEkishor pokar
 
Real life Application of maximum and minimum
Real life Application of maximum and minimumReal life Application of maximum and minimum
Real life Application of maximum and minimumNiloy Biswas
 
Eigenvalues and Eigenvectors
Eigenvalues and EigenvectorsEigenvalues and Eigenvectors
Eigenvalues and EigenvectorsVinod Srivastava
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebragavhays
 
Digital systems logicgates-booleanalgebra
Digital systems logicgates-booleanalgebraDigital systems logicgates-booleanalgebra
Digital systems logicgates-booleanalgebraelfeds916
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisRadhika Talaviya
 
Number theory and cryptography
Number theory and cryptographyNumber theory and cryptography
Number theory and cryptographyYasser Ali
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 

Mais procurados (20)

Combinatorics.pptx
Combinatorics.pptxCombinatorics.pptx
Combinatorics.pptx
 
Coin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic ProgrammingCoin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic Programming
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
 
Complex Eigenvalues
Complex EigenvaluesComplex Eigenvalues
Complex Eigenvalues
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Generating functions solve recurrence
Generating functions solve recurrenceGenerating functions solve recurrence
Generating functions solve recurrence
 
Gauss jordan and Guass elimination method
Gauss jordan and Guass elimination methodGauss jordan and Guass elimination method
Gauss jordan and Guass elimination method
 
Higher Differential Equation
Higher Differential Equation Higher Differential Equation
Higher Differential Equation
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Methods of solving ODE
Methods of solving ODEMethods of solving ODE
Methods of solving ODE
 
Real life Application of maximum and minimum
Real life Application of maximum and minimumReal life Application of maximum and minimum
Real life Application of maximum and minimum
 
Eigenvalues and Eigenvectors
Eigenvalues and EigenvectorsEigenvalues and Eigenvectors
Eigenvalues and Eigenvectors
 
Time complexity
Time complexityTime complexity
Time complexity
 
Pigeon hole principle
Pigeon hole principlePigeon hole principle
Pigeon hole principle
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
Digital systems logicgates-booleanalgebra
Digital systems logicgates-booleanalgebraDigital systems logicgates-booleanalgebra
Digital systems logicgates-booleanalgebra
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
K - Map
  K - Map    K - Map
K - Map
 
Number theory and cryptography
Number theory and cryptographyNumber theory and cryptography
Number theory and cryptography
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 

Semelhante a GCD.ppt

Problems and solutions, inmo 2011
Problems and solutions, inmo 2011Problems and solutions, inmo 2011
Problems and solutions, inmo 2011askiitians
 
Chapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdfChapter 2 Lecture Notes_ Divisibility.pdf
Chapter 2 Lecture Notes_ Divisibility.pdfgeorgianabeauty02
 
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 KVKMD. G R Ahmed
 
NumberTheory.ppt
NumberTheory.pptNumberTheory.ppt
NumberTheory.pptDhandhan16
 
Abstract Algebra Beamer Lesson1
Abstract Algebra Beamer Lesson1Abstract Algebra Beamer Lesson1
Abstract Algebra Beamer Lesson1Monica Waters
 
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.svidyabhoge1
 
555_Spring12_topic06.ppt
555_Spring12_topic06.ppt555_Spring12_topic06.ppt
555_Spring12_topic06.pptSnehSinha6
 
GCD of n Numbers
GCD of n NumbersGCD of n Numbers
GCD of n NumbersSaikat Roy
 
Complete ncert exemplar class 10
Complete ncert exemplar class 10Complete ncert exemplar class 10
Complete ncert exemplar class 10physicsmaths5
 
X ch 1 real numbers
X  ch 1  real numbersX  ch 1  real numbers
X ch 1 real numbersAmruthaKB2
 
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 |Slides With 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.docxbagotjesusa
 

Semelhante a 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
 

Último

Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?RemarkSemacio
 
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 Dubaikojalkojal131
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxAniqa Zai
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...HyderabadDolls
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...HyderabadDolls
 
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...HyderabadDolls
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareGraham Ware
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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
 
20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdfkhraisr
 
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 FLaNKTimothy Spann
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRajesh Mondal
 
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...HyderabadDolls
 
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
 
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.pptxchadhar227
 

Último (20)

Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?
 
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
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptx
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
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...
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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...
 
20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf
 
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
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
Lake Town / Independent Kolkata Call Girls Phone No 8005736733 Elite Escort S...
 
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...
 
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
 

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).