# gcd

Returns the greatest common divisor of the given integers.

Wikipedia:

$$\operatorname{gcd}(54,24)$$

The number 54 can be expressed as a product of two integers in several different ways:

$$54\times 1=27\times 2=18\times 3=9\times 6.$$

Thus the complete list of divisors of 54 is: $$1,2,3,6,9,18,27,54$$

Similarly, the divisors of 24 are: $$1,2,3,4,6,8,12,24$$

The numbers that these two lists have in common are the common divisors of 54 and 24, that is: $$1,2,3,6$$

Of these, the greatest common divisor is 6.

gcd(a,b)
Returns the greatest common divisor of the given integers.
COPY/// @func   gcd(a,b)
///
/// @desc   Returns the greatest common divisor of the given integers.
///
/// @param  {real}      a           positive integer
/// @param  {real}      b           positive integer
///
/// @return {real}      greatest common divisor
///

function gcd(a, b)
{
while (b != 0) {
var r = a mod b;
a = b;
b = r;
}
return abs(a);
}


Contributors: xot

GitHub: View · Commits · Blame · Raw
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}