At some point you mentioned it was possible to divide N by a backref. Do you actually have a way to do this in the general case? The chinese trick is cool but afaict it only works if (N / backref) is coprime with backref or backref - 1.
@Grimy You need much more than just that. You need the set of primes that remain to add to the product. That's three numbers.
Please give a better hint. Or if you don't want to explain it to me so I can implement my own version of it, just post it on Calculate Euler's totient function.
Either way you'd be credited. If I ended up making one less than 194 characters, I'd credit you with the idea, and if not, then you'd be the one to post anyway.
I don’t understand why you’d need a third number. If you add them in order, the set of primes that remain to be added are those > the last prime added.
Maybe you're just so amazing at doing this that you don't understand what the challenge of it is...
To know what prime to do next, you need to have the set of primes that haven't been done yet.
Which in the simplest way would mean having the original N with all the already-handled primes divided off. But there can't be room for both that and your two-numbers-in-one.
But how can you keep track of both N * (all of the (p-1)/p for the smaller primes handled so far) and which is the largest prime you've handled so far?
The largest prime handled so far is still going to be less than that
I do (?=(?:(xx+)\1*(?=\1$))*(x*)), which is the same length as your (?=((?=(xx+)(\2+$))\3)*(x*)) but uses 2 fewer capture groups, saving chars on later backrefs
Hmm, weird, I tagged ^((?=(xx+)(\2+$))\3)*\Kx* as a later version than ^((xx+)\2*(?=\2$))*\Kx* in my collection of regexes, but the earlier version is better and is the same as what you changed it to
I didn't bother looking at the earlier versions and just grabbed the latest one to use