euclid-GCD-algorithm
May 4, 2015
algorithm
GCD is the greatest common divisor,for example the GCD of 20 and 30 is 10, the GCD of 42 and 63 is 21.
the key to find the GCD can demostrate below:
use the previous example
eg. 42 = 212 and 63 = 213 so 63 - 42 = 21(3-2) = 21, and the 21 is also the GCD of 42 and 21, repeat the process, finally
the both number is the same, and we find the answer
implements with javascript
1 | function gcd(a, b) { |
本文作者:oldmee
本文链接:https://oldmee.github.io/2015/05/04/euclid-GCD-algorithm/
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。