Improved Euclidean Algorithm

Before this, knowReduction Modulo N vs. Euclidean Division by N

Interactive · 2 questions

Recall that the Greatest Common Divisor (gcd) of two integers A and B is the largest integer that divides both A and B.

The Euclidean Algorithm is a technique for quickly finding the gcd⁡\gcd of two integers.

The Algorithm

The Improved Euclidean Algorithm is based on a simple theorem: gcd⁡(A,B)=gcd⁡(A,B(modA))\gcd(A,B) = \gcd(A,B \pmod{A}) and a little lemma gcd⁡(A,B)=gcd⁡(B,A)\gcd(A,B) = \gcd(B,A)

where B(modA)B \pmod{A} means the quotient remainder of B when taking modulus of A.

The Euclidean Algorithm for finding gcd⁡(A,B)\gcd(A,B) for positive integers A, B is as follows:

  • If A = 0 then gcd⁡(A,B)=gcd⁡(0,B)=B\gcd(A,B)=\gcd(0,B)=B, and we can stop.
  • If B = 0 then gcd⁡(A,B)=gcd⁡(A,0)=A\gcd(A,B)=\gcd(A,0)=A, and we can stop.
  • Otherwise, write AA as B∗Q+RB*Q+R, where QQ is an integer and 0≤R≤B0 \leq R \le B. According to the theorem above, gcd⁡(A,B)=gcd⁡(B,R)\gcd(A,B) = \gcd(B,R), where A+B>B+RA+B>B+R.

What if these steps keeps recurring without giving us an answer?

Don't worry, the algorithm must terminate at some step.

The sum of the two numbers in parenthesis, which is a positive integer, can't decrease forever. Remember part of the [definition of an integer] is that it is made up of finitely many 11s? When we say A+B>B+RA+B>B+R, the difference between A+BA+B and B+RB+R must be a positive integer, so we have took at least 11 from A+BA+B in this step. We can only take 11s from A+B for finitely many times, so the algorithm always terminates.

Example: Finding the GCD of 270 and 192

A=270, B=192

Step 1: Check that A ≠ 0

Step 2: Check that B ≠ 0

Step 3: Use long division to find that 270/192 = 1 with a remainder of 78. We can write this as: 270=192∗1+78270 = 192 * 1 +78 The original problem is reduced to: Find gcd⁡(192,78)\gcd(192,78), since gcd⁡(270,192)\gcd(270,192) = gcd⁡(192,78)\gcd(192,78)

A=192, B=78

Step 1: Check that A ≠ 0

Step 2: Check that B ≠ 0

Step 3: Use long division to find that 192/78 = 2 with a remainder of 36. We can write this as: 192=78∗2+36192 = 78 * 2 + 36 The original problem is reduced to: Find gcd⁡(78,36)\gcd(78,36), since gcd⁡(192,78)\gcd(192,78)=gcd⁡(78,36)\gcd(78,36)

A=78, B=36

Step 1: Check that A ≠ 0

Step 2: Check that B ≠ 0

Step 3: Use long division to find that 78/36 = 2 with a remainder of 6. We can write this as: 78=36∗2+678 = 36 * 2 + 6 The original problem is reduced to: Find gcd⁡(36,6)\gcd(36,6), since gcd⁡(78,36)\gcd(78,36)=gcd⁡(36,6)\gcd(36,6)

A=36, B=6

What is our next step after checking that A ≠ 0 and B ≠ 0?

Choose one answer

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems