Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I changed the FactorInteger output to a format which is more suitable to my needs.

I used:

f[x_] := Array[x[[1]] &, x[[2]]]
fac[n_] := Flatten[Map[f[#] &, FactorInteger[n]]]


fac[24] yields {2,2,2,3}

Now, for presentation purposes only, I would like

{2^3, 3}

as the result of the function fac.

I tried several things such as:

HoldForm[2^3], which yields 2^3 as I would like, but

using the function

g[x_] := HoldForm[x[[1]]^x[[2]]] in fac instead of f

gives unexpected results.

How can I present the results of FactorInteger n as

{p1^a1, p2^a2, ... ,pn^an} i.e. ( 2^2, 5^3, 7 } ?
share|improve this question
up vote 5 down vote accepted
Inactive[Power] @@@ FactorInteger[24] /. Inactive[Power][a_, 1] :> a

enter image description here

Your fac[24] could be written as

Flatten[ConstantArray @@@ FactorInteger[24]]

enter image description here

To not show the ^ symbol:

Superscript @@@ FactorInteger[24] /. Superscript[a_, 1] :> a

enter image description here

share|improve this answer
Much better already but I don't want the ^ symbol in 2^3, I want the 3 lifted to the exponent place $2^3$ ( should have used Latex in question I suppose ). I tried adding //TraditionalForm but that did not work. – nilo de roock Jan 11 at 21:53
See update ------------------------------------- – eldo Jan 11 at 22:01

From the docs:

CenterDot @@ Superscript @@@ FactorInteger[7!]

enter image description here

Though CenterDot does not work well for prime powers:

CenterDot @@ Superscript @@@ FactorInteger[5]

enter image description here

If this is a problem, you could just define your own:

myCenterDot[e_] := e
myCenterDot[args__] := CenterDot[args]

Now it works fine:

myCenterDot @@ Superscript @@@ FactorInteger[5]

enter image description here

You could do something similar for Superscript if you don't want to see 1 in the exponents.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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