CalcGcd

CalcGcd

CalcGcd[ n1, n2, ... ] returns the greatest common divisor of integers.

Usages

CalcGcd[ n1, n2, ... ]

CalcGcd[ n1, n2, ... ] returns the largest positive integer that divides all of n1, n2, ....

Example in out
The greatest common divisor of 2 and 6. CalcGcd[ 2, 6 ] 2
Three numbers. CalcGcd[ 6, 12, 15 ] 3
The result is always positive. CalcGcd[ -6, 2 ] 2

CalcGcd[ list ]

The numbers can also be given as a list. Lists inside the list are included as well.

Example in out
The numbers in a list. CalcGcd[ {6, 12, 15} ] 3
Nested lists. CalcGcd[ {4, {6, 8} } ] 2
Details
  • Zero: CalcGcd[ 0, 5 ] returns 5 and CalcGcd[ 0, 0 ] returns 0.
  • Single number: CalcGcd[ -6 ] returns 6.
  • Non-integers: if an argument is not an integer (such as x or 2.5), CalcGcd is left unevaluated: CalcGcd[ 4, 6, x ] stays CalcGcd[ 4, 6, x ]. However, if the numbers before it already have greatest common divisor 1, the result is 1: CalcGcd[ 2, 3, x ] returns 1.
  • No arguments: CalcGcd[] is left unevaluated.

See also: CalcLcm, CalcDivisors, FactorInt