Yeah, it's a nice thing indeed, thank you for sharing it
I haven't coded anything up for this, because it's just a first idea and I think it would be horrible to code (and I'm exhausted from doing the T2 challenge).. but how about using two primes above whatever the function uses as a "store"...
One prime (let's say 7) will be a count of bits used per prime, and the other (say 11) will be huge, being a concatted sequence of binary numbers.
eg: before the call we have 2*2*2*3*5*5*5*5*7*11*11*13
In our call we use 2,3,5. 7 and 11 are used for this. 13 we can leave alone.
So we store as follows before we do any of our call:
Maximum number of bits needed is 3 (to store four 5s). So we have 7*7*7.
then we have three bits for each of 2,3,5,7,11:
2: 3 - 011
3: 1 - 001
5: 4 - 100
7: 1 - 001
11: 2 - 010
concat them all: 011 001 100 001 010 = 0x330A = 13066decimal.
So we create 11^13066. This may seem a bit excessive (it is, I'm sure), but it leaves all the information intact so as long as it's possible to do the encoding.... now I think about it, maybe that's the difficulty here, not representing it... how do you start the sequence off without losing anything, if you can't assume that any particular prime is free? How do you know that whatever possible "first" step is done was not the state beforehand, if you see what I mean... maybe the key is to always dedicate one/two/whatever as free and available at the start of calls? You tell me mike!
I've left this reply cleartext because I think it suits more of a discussion now... and if people are scrolling down this far anyway they probably deserve it

But someone feel free to edit me if you disagree.
Will