Greatest common divisor
2006-09-15 14:15
232 查看
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
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
相关文章推荐
- BestCoder Round 38-1002 Greatest Greatest Common Divisor
- GCD (greatest common divisor)【求最大公约数】
- 最大公倍数_Greatest Common Divisor
- Greatest Greatest Common Divisor hdu 5207
- Algorithms - 最大公约数(greatest common divisor)-欧几里得(Euclid) 算法 及 代码
- ssu 499 Greatest Greatest Common Divisor
- The Greatest Common Divisor
- P32 (**) Determine the greatest common divisor of two positive integer numbers.
- Greatest Common Divisor (GCD) - Euclidean algorithm
- hdu 5207 Greatest Greatest Common Divisor
- HDU 5207 Greatest Greatest Common Divisor
- Algorithms - 最大公约数(greatest common divisor)-欧几里得(Euclid) 算法 及 代码
- P32 (**) Determine the greatest common divisor of two positive integer numbers.
- HDU 5207 Greatest Greatest Common Divisor
- hdu 5207 Greatest Greatest Common Divisor(筛法求公约数)
- BestCoder Round #38 1002——数学——Greatest Greatest Common Divisor
- 【HDU 5207】Greatest Greatest Common Divisor —— 最大公因子
- SGU 499:Greatest Greatest Common Divisor
- GCD (Greatest Common Divisor)
- 最大公约数GCD(Greatest Common Divisor)算法小结