Log in to add a comment

Log in to add a comment

( hcf of two positive integers a and b is the largest positive integer d that divides both a and b)

rk−2 = qk rk−1 + rk where rk < rk−1. In other words, multiples of the smaller number rk−1 are subtracted from the larger number rk−2 until the remainder is smaller than the rk−1.In the initial step (k = 0), the remainders r−2 and r−1 equal a and b, the numbers for which the GCD is sought. In the next step (k = 1), the remainders equal b and the remainder r0of the initial step, and so on. Thus, the algorithm can be written as a sequence of equations

a = q0 b + r0

b = q1 r0 + r1

r0 = q2 r1 + r2

r1 = q3 r2 + r3…

If a is smaller than b, the first step of the algorithm swaps the numbers. For example, if a < b, the initial quotient q0 equals zero, and the remainder r0 is a. Thus, rk is smaller than its predecessor rk−1 for all k ≥ 0.Since the remainders decrease with every step but can never be negative, a remainder rN must eventually equal zero, at which point the algorithm stops. The final nonzero remainder rN−1 is the greatest common divisor of a and b. The number N cannot be infinite because there are only a finite number of nonnegative integers between the initial remainder r0 and zero.