FactorInt
FactorInt
FactorInt[ n ] returns the prime factorisation of a positive integer.
Usages
FactorInt[ n ]
FactorInt[ n ] returns a list {primes, exponents}, such that n is the product of each prime to the power of its exponent. n must be a positive integer.
| Example | in | out |
|---|---|---|
90 = 21 · 32 · 51. |
FactorInt[ 90 ] |
{ {2, 3, 5}, {1, 2, 1} } |
| A script variable. | x := 35 |
r = { {5, 7}, {1, 1} } |
| A prime number. | FactorInt[ 17 ] |
{ {17}, {1} } |
1 has no prime factors. |
FactorInt[ 1 ] |
{ {}, {} } |
FactorInt[ list ]
If the argument is a list, each element is factorised.
| Example | in | out |
|---|---|---|
| Factorise two numbers. | FactorInt[ {12, 15} ] |
{ { {2, 3}, {2, 1} }, { {3, 5}, {1, 1} } } |
Details
- Calculated numbers: the argument must already be a number. In a script,
FactorInt[ 3*17 ]is left unevaluated, because3*17is not calculated. UseFactorInt[ CalcTimes[3, 17] ]instead. - Large numbers: numbers larger than
1021are left unevaluated.
| Invalid input | Result |
|---|---|
FactorInt[ 0 ], FactorInt[ -12 ] |
Left unevaluated: n must be positive. |
FactorInt[ 2.5 ], FactorInt[ x ] |
Left unevaluated: n must be an integer. |
Warning
- The primes are not always in ascending order. For example,
FactorInt[ 51 ]returns{ {17, 3}, {1, 1} }. If you need them in order, sort them withSortI:F := FactorInt[1938]
I := SortI[F[[1]]]
P := Map[i -> F[[1]][[i]], I]
E := Map[i -> F[[2]][[i]], I]
givesP = {2, 3, 17, 19}andE = {1, 1, 1, 1}. - Prime factors larger than about
2·109are not handled correctly and give a wrong result.
See also: CalcDivisors, CalcGcd, SortI