Euclidean algorithm

1
2
3
4
5
int gcd(int a,int b) {
if(b==0)
return a;
return gcd(b,a%b);
}

1. Make

-

-

c is the biggest divisor

2. Got

3. c is a divisor of r as well.

4. m-kn and n definitely has coprime relation

proof by contradiction

  1. setting they are no coprime relation

    -
    (d>1)

  2. then

    -

    -

  3. a and b ‘s biggest divisor is not c. so step 4 proved.

5. c is biggest divisor in b and r as well.

-