Though there is a prime factorization challenge and it's here, this, I feel, will be a bit more interesting than that one.
To understand this, let's have an example; I will use 5,184 for this. \$5184 = 2^6 \times 3^4\$. However, for this challenge, such a factorization is insufficient - the reason is that 6 and 4 are composite - therefore, we must factorize them too: \$5184 = (2^{2*3}) \times (3^{2^2})\$. This containes a total of 0 composite numbers, so we are done.
Your task is to prime-factorize a number. However, unlike in here, if you see a composite number in the exponent, you must then factorize this too.
Input will be a number or a string, and output can be a nested array, nested list, or string.
You must use the fewest numbers necessary: 65536 is \$2^{2^{2^2}}\$, not \$ 2^{2 \times 2 \times 2 \times 2}\$ or anything similar - however, \$2^{2^2}\$ and \$2^{2 \times 2}\$ are identical and as such, can be used freely - make of it what you will.
Some example answers to show the format:
5184, 65536 - see above
\$2^{144} = 2^{2^{2^2} \times 3^2}\$ or [2, [2, [2, 2], [3, [2]]]]
, or "2^(2^2^2)*(3^2)"
, where the brackets are necessary to separate the terms.
\$5^{125} = 5^{5^3}\$, or [5, [5, [3]]]
, or 5^5^3
(note, as \$a^{b^c} == a^{(b^c)}\$, the brackets are not necessary.
\$47,258,883 = 3^9 \times 7^4 = 3^{3 \times 3} \times 7^{2 \times 2}\$ or \$3^{3^2} \times 7^{2^2}\$ or [3, [3, 2], 7, [2, 2]]
or [3, [3, [2]], 7, [2, [2]]]
or 3^(3 \times 3) \times 7^(2 \times 2)
or 3^3^2 \times 7^2^2
\$2^{81} = 2^{3^{2 \times 2}}\$ or similar (see above)
\$5^{343} * 7^{125} = 5^{7^3} \times 7^{5^3}\$ or similar (see above)
And finally, to check your prime factorization technique:
\$2^{2162160} \times 3^{1441440} \times 5^{1081080} = 2^{2^{2^2} \times 3^3 \times 5 \times 7 \times 11 \times 13} \times 3^{2^5 \times 3^2 \times 5 \times 7 \times 11 \times 13} \times 5^{2^3 \times 3^3 \times 5 \times 7 \times 11 \times 13}\$
You may pick any output format and use any non-number or newline separator, and you may include any number of trailing/leading newlines in output, but you must be consistent about your choice and state it in your answer.
As always, this is code-golf - shortest code wins.
2^144
should become[2, [[2, [2, 2]], [3, 2]]]
. \$\endgroup\$9
is not3^3
(so47258883
should be[[3, [3, 2]], [7, [2, 2]]]
). Apologies for not noticing these earlier; I'm just noticing inconsistencies with my solution \$\endgroup\$