0
$\begingroup$

If I do

FactorInteger[120]

I get

{{2, 3}, {3, 1}, {5, 1}}

which is correct of course, but how do I get it as or change it to

{2, 2, 2, 3, 5}

?

| improve this question | | | | |
$\endgroup$
3
$\begingroup$

Here's one way:

ConstantArray[#[[1]], #[[2]]] & /@ FactorInteger[120] // Flatten

{2, 2, 2, 3, 5}
| improve this answer | | | | |
$\endgroup$
  • 9
    $\begingroup$ You can make this even more slick with ConstantArray @@@ FactorInteger[120] // Flatten $\endgroup$ – jjc385 Mar 31 '17 at 17:57
  • 2
    $\begingroup$ In version 10.2 or later you could also use Table @@@ FactorInteger[120] // Flatten $\endgroup$ – Bob Hanlon Mar 31 '17 at 23:56
  • $\begingroup$ This is what I love about this site -- there's always better ways of doing things! $\endgroup$ – bill s Apr 1 '17 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.