Generating all factors

steponic shared this question 1 year ago
Answered

Hi everyone,


PrimeFactors(n) gives a list with the prime factors of n.

How might I use that to generate all the factors of n?

I.e., PrimeFactors(12)={2,2,3}

I would like to generate the list {1,2,3,4,6,12}.

I can imagine generating all multiplication iterations of {a1, a2, a3, ..., an}, pulling out the unique results, and appending 1. Is there an easier or more elegant way?


Any ideas?

Comments (2)

photo
3

divisorslist(number)

photo
1

LOL. Yep, that would be both easier and more elegant... Thanks!

© 2020 International GeoGebra Institute