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 ]returns5andCalcGcd[ 0, 0 ]returns0. - Single number:
CalcGcd[ -6 ]returns6. - Non-integers: if an argument is not an integer (such as
xor2.5),CalcGcdis left unevaluated:CalcGcd[ 4, 6, x ]staysCalcGcd[ 4, 6, x ]. However, if the numbers before it already have greatest common divisor1, the result is1:CalcGcd[ 2, 3, x ]returns1. - No arguments:
CalcGcd[]is left unevaluated.
See also: CalcLcm, CalcDivisors, FactorInt