Greatest common divisor

We define the greatest common divisor of two integers m and n is the largest integer that divides them both. gcd(m,n) = max{k | k/m and k/n}.

One of the nicest properties of the gcd is that it is easy to computer,using a 2300-year-old method called Euclid's algorithm: gcd(0,n) = n; gcd(m,n) = gcd(m,n mod m) [0<=m<n] ;For example , gcd(12,18) = gcd(6,12) = gcd(0,6) = 6. We can extend it that m' *m+n'*n = gcd(m,n).

Now let we prove it.

Let r = n mod m and gcd = gcd(m,n), we have n=k*m+r; and (m mod gcd) =0,(n mod gcd) = 0

∴ (k*m+r) mod gcd = 0.

∴ we have t and f, t*gcd = k*m+r; f*gcd = m

∴r=(t-k*f)gcd;

∴ r mod gcd =0

 

你可能感兴趣的:(Greatest common divisor)