Revision 5918a84e-0d4e-4d72-a91e-cf2eb7ab8bd3 - Code Golf Stack Exchange
# Mathematica, <s>175</s> <s>177</s> 169 bytes
Join@@@Table[f@x,{s,{1,-1}},{x,r@#},x[[2]]s]&@*(If[#==1,1,{p,e}=(f=First)@MaximalBy[(r=FactorInteger)@#,f];q=1~Max~NextPrime[p,-1];(p/q)^e#0[#(1##&@@Range[q+1,p])^-e]]&)
[Try it online!](https://tio.run/##DY7hasMgGEVfRRCC2b6S2rHBKMJHC4EONsbYP7HginaBaBJjwSHpq2f@ulw4l3Odjr/G6dhd9GpvXqxvQ@cR8Vv/9EZaTJBnyBw2fFkgJwhIF0hS7pSaVYUP7GQlFYIDhzyCWQSzou3CHGt816lzuj/8SRZEqy9xCCcfzdWEGilYtZ8Evxfo/mFS/AydM3IsHrVnYzPVZ0O3kjJOaYX4pf3VyOmRw6jq88YoVdVrmfiIx6G/Od8OwcnynzRIMt82r0B2QJ6A8Oa5ZFPKy6LWfw "Wolfram Language (Mathematica) – Try It Online")
### How it works
This is the composition of two functions. The first, which ungolfs to
If[#==1,
1,
{p,e}=(f=First)@MaximalBy[(r=FactorInteger)@#,f];
q=1~Max~NextPrime[p,-1];
(p/q)^e #0[#(1##&@@Range[q+1,p])^-e]
]&
is a recursive function for actually computing the desired numbers. Given input `x`, we find the largest prime factor `p` appearing in `x` (to the power `e`), let `q` be the prime before `p`, and recurse on `x*(p!/q!)^-e`. (So, for example, given `x=10/9` we'd pull out a factor of `5!/3!` and recurse on `1/18`.)
This function computes the result, but (to cancel like factors) it writes the result as a rational number. For example, `10/9` gets mapped to `2*5/3*3*3 = 10/27`, which we want to convert to the list `{{2,5},{3,3,3}}`. That's what the second part,
Join@@@Table[f@x,{s,{1,-1}},{x,r@#},x[[2]]s]&
does: for `s=1` (positive powers) and `s=-1` (negative powers), and for each term `{prime,exponent}` in the factorization `r@#`, we repeat the prime number `prime` `exponent*s` many times.
# Noncompeting version with 129 bytes
If[∇1=1;#==1,1,{p,e}=(f=First)@MaximalBy[FactorInteger@#,f];q=1~Max~NextPrime[p,-1];(∇p/∇q)^e#0[#(1##&@@Range[q+1,p])^-e]]&
Same as above, but instead of giving output as a list, gives output as an expression, using the ∇ operator (because it has no built-in meaning) as a stand-in for factorials. Thus, an input of `10/9` gives an output of
(∇2 ∇5)/(∇3)^3
This is shorter because we skip the second part of the function.
----------
*+2 bytes: the assignment `f=First` has to be done in the right place to keep Mathematica from getting upset.*
*-8 bytes: fixed a bug :)*