Firstly, you really do not need a complete simple decomposition, but only decomposition into primes smaller than your base (I think you have 10 in mind here, but the problem can be generalized to any base). Thus, we only need to factorize into the first 4 primes: 2, 3, 5 and 7. If the stop coefficient (simple or not) is greater than 1, then the problem has 0 solutions.
Now let's assume that the number p taken into account in:
p = 2^d1 * 3^d2 * 5^d3 * 7^d4
and also consists of digits n :
p = d (n-1) d (n-2) ... d 2 d 1 d 0
Then, reordering the numbers will also be:
p = 2^q2 * 3^q3 * 4^q4 * 5^q3 * ... * 9^q9
where qi >= 0 and q2 + q3 + ... q9 = n
as well (due to factorization):
for prime=2: d1 = q2 + 2*q4 + q6 + 3*q8 for prime=3: d2 = q3 + q6 + 2*q9 for prime=5: d3 = q5 for prime=7: d4 = q7
So, q7 and q7 fixed, and we need to find all non-negative integer solutions of the equations: (where unknowns are the remaining qi : q2, q3, q4, q6, q8 and q9 )
d1 = q2 + 2*q4 + q6 + 3*q8 d2 = q3 + q6 + 2*q9 n - d3 - d4 = q2 + q3 + q4 + q6 + q8 + q9
For each of the above solutions, there are several permutations of numbers that can be found by the formula:
X = n! / ( q2! * q3! * ... q9! )
to be summarized.
There can be a closed formula for this, using the generation functions, you can publish it on Math.SE
Example for p=24 , n=3 :
p = 2^3 * 3^1 * 5^0 * 7^0
and we have:
d1=3, d2=1, d3=0, d4=0
Entire solutions for:
3 = q2 + 2*q4 + q6 + 3*q8 1 = q3 + q6 + 2*q9 3 = q2 + q3 + q4 + q6 + q8 + q9
are (q2, q3, q4, q6, q8, q9) = :
(2, 0, 0, 1, 0, 0) (1, 1, 1, 0, 0, 0)
which give:
3! / ( 2! * 1! ) = 3 3! / ( 1! * 1! * 1! ) = 6
and 3+6 = 9 complete solutions.
Example for p=3628800 , n=10 :
p = 2^8 * 3^4 * 5^1 * 7^1
and we have:
d1=8, d2=4, d3=1, d4=1
Entire solutions for:
8 = q2 + 2*q4 + q6 + 3*q8 4 = q3 + q6 + 2*q9 8 = q2 + q3 + q4 + q6 + q8 + q9
are (q2, q3, q4, q6, q8, q9) (together with the corresponding digits and permutations of the solution):
(5, 0, 0, 0, 1, 2) 22222899 57 10! / (5! 2!) = 15120 (4, 0, 2, 0, 0, 2) 22224499 57 10! / (4! 2! 2!) = 37800 (4, 1, 0, 1, 1, 1) 22223689 57 10! / (4!) = 151200 (3, 2, 1, 0, 1, 1) 22233489 57 10! / (3! 2!) = 302400 (4, 0, 1, 2, 0, 1) 22224669 57 10! / (4! 2!) = 75600 (3, 1, 2, 1, 0, 1) 22234469 57 10! / (3! 2!) = 302400 (2, 2, 3, 0, 0, 1) 22334449 57 10! / (3! 2! 2!) = 151200 (2, 4, 0, 0, 2, 0) 22333388 57 10! / (4! 2! 2!) = 37800 (3, 2, 0, 2, 1, 0) 22233668 57 10! / (3! 2! 2!) = 151200 (2, 3, 1, 1, 1, 0) 22333468 57 10! / (3! 2!) = 302400 (1, 4, 2, 0, 1, 0) 23333448 57 10! / (4! 2!) = 75600 (4, 0, 0, 4, 0, 0) 22226666 57 10! / (4! 4!) = 6300 (3, 1, 1, 3, 0, 0) 22234666 57 10! / (3! 3!) = 100800 (2, 2, 2, 2, 0, 0) 22334466 57 10! / (2! 2! 2! 2!) = 226800 (1, 3, 3, 1, 0, 0) 23334446 57 10! / (3! 3!) = 100800 (0, 4, 4, 0, 0, 0) 33334444 57 10! / (4! 4!) = 6300
which is a 2043720 complete solution if I have not made any mistakes.