Skip to content
← All questions

Why is the last non-zero remainder rnr_n the gcd⁡(a,b)\gcd(a,b)?

The last non-zero remainder rnr_n is the gcd⁡(a,b)\gcd(a,b) because the Euclidean algorithm preserves the greatest common divisor at each step: gcd⁡(a,b)=gcd⁡(b,r1)=gcd⁡(r1,r2)=⋯=gcd⁡(rn,0)\gcd(a,b) = \gcd(b,r_1) = \gcd(r_1,r_2) = \dots = \gcd(r_n, 0). Since any number divides 0, the greatest common divisor of rnr_n and 0 is simply rnr_n itself.

Conditions

  • The algorithm terminates when the remainder is 0.
  • rnr_n is the last non-zero remainder in the sequence.

Reasoning, step by step

  1. Recall the invariant gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b) = \gcd(b, a \bmod b).
  2. Apply it repeatedly to get gcd⁡(a,b)=gcd⁡(rn,rn+1)\gcd(a,b) = \gcd(r_n, r_{n+1}).
  3. Note that the algorithm stops when rn+1=0r_{n+1} = 0.
  4. Conclude that gcd⁡(rn,0)=rn\gcd(r_n, 0) = r_n, so gcd⁡(a,b)=rn\gcd(a,b) = r_n.

Example

The video shows the final step rn−1=qn+1rn+0r_{n-1} = q_{n+1}r_n + 0 and concludes d=gcd⁡(a,b)=rnd = \gcd(a,b) = r_n, emphasizing that the answer is the last non-zero remainder, not the 0.

Common misconceptions

  • Mistaking the final remainder 0 as the greatest common divisor.
  • Believing that the greatest common divisor is the quotient of the last division.

Watch the explanation

Connected concepts

Explore next

Related questions

Understand why

↗
Find a method

↗
Find a method

↗
Find a method

↗
Understand why

↗

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.