Definition: | sequence s = prime_factors(integer n, bool duplicates=false) |
Description: |
Returns a list of prime factors of n.
Note that, when duplicates is false, prime_factors() always returns {} when passed a prime number. When duplicates is true, for all numbers >=2, returns a list such that multiplying all the elements of it together produces the value n, ie a true decomposition. |
Example: |
s = prime_factors(6) -- s is {2,3} s = prime_factors(720) -- s is {2,3,5} s = prime_factors(12345) -- s is {3,5,823} s = prime_factors(27) -- s is {3} s = prime_factors(27,duplicates:=true) -- s is {3,3,3} In contrast, factors(720) is {2, The use of a named parameter when setting the duplicates flag is recommended, to make the intent clear and the code easier to read. |
See Also: | factors |