CalcDivisors
CalcDivisors
CalcDivisors[ n ] returns all positive divisors of an integer, in ascending order.
Usages
CalcDivisors[ n ]
CalcDivisors[ n ] returns a list of all positive integers that divide n, from small to large. The list always starts with 1 and ends with the absolute value of n.
| Example | in | out |
|---|---|---|
The divisors of 12. |
CalcDivisors[ 12 ] |
{1, 2, 3, 4, 6, 12} |
| A prime number has two divisors. | CalcDivisors[ 13 ] |
{1, 13} |
| A script variable. | x := 16 |
r = {1, 2, 4, 8, 16} |
Details
- Negative numbers give the same divisors as the positive number:
CalcDivisors[ -12 ]returns{1, 2, 3, 4, 6, 12}. CalcDivisors[ 1 ]returns{1}.- Large numbers: numbers larger than
1000000(in absolute value) are left unevaluated. - Lists are not supported. Use
Mapto apply it to each element.
| Invalid input | Result |
|---|---|
CalcDivisors[ 0 ] |
Error: Cannot calculate the divisors of zero |
CalcDivisors[ 2.5 ], CalcDivisors[ x ], CalcDivisors[ {4, 6} ] |
Error: the argument should be an integer |
CalcDivisors[ 12, 2 ] |
Error: the number of arguments should be 1 |