# Listing products of prime powers

Given a positive integer $n$, what is the code to list $2^{a_2}3^{a_3}\cdots p^{a_p}$, where $a_i\ge 0$ are integers, with respect to the lexicographic ordering on $(a_2,a_3,\ldots, a_p)$?

The only idea that comes to mind is

Product[Prime[p]^(a_p), {p,1,PrimePi[n]}]


I know that the $a_p$ in the parenthesis is incorrect, but I am not sure what to put there and how to index the exponents since the Product code only allows one index (in my case, $p$).

• Does Times @@ (Prime /@ Range[n]^Array[a, n]) work for you? – aardvark2012 Oct 6 '17 at 10:52
• What do you mean by "with respect to the lexicographic ordering" on the powers? The term "lexicographic ordering" makes sense only when comparing two elements of the product of sets (in the strictly set-theoretic sense). Do you perhaps really mean simply that the powers of primes should be arranged in the order of the exponents rather than in the order of the primes? – murray Nov 6 '17 at 15:36

It's unclear in your question how $n$ relates to what you want. If you are trying to express the prime-power factorization of a given integer $n \geq 2$, then the built-in function FactorInteger does most of the work, e.g.:

    n = 39510856;
FactorInteger[n]
(* {{2, 3}, {7, 4}, {11, 2}, {17, 1}} *)


If that's the essence of what you want, but you want an explicit product of prime powers expression, the following will do it:

    pPower[{p_, a_}] := HoldForm[p^a]
Times @@ pPower /@ FactorInteger[n]


The output will look like: $2^3\, 7^4\, 11^2\, 17^1$. (I don't know how to use markup to make that expression appear within the indented code block above!)

Use Subscript. For instance with n = 5:

Product[Prime[p]^(Subscript[a, p]), {p, 1, PrimePi}]

• Is there a way to place bounds on $a_p$ in your code? – The Substitute Oct 6 '17 at 10:58
• Note sure what you mean by that. You want to set the min and max value of ap ? Can you give an example ? – Lotus Oct 6 '17 at 11:05

From the Applications section of FactorInteger

n = 39510856;

CenterDot @@ (Superscript @@@ FactorInteger[n]) (% /. {Superscript -> Power, CenterDot -> Times}) == n

(* True *)