Optimize the shortest form of matching powers of N where N is a constant

This is not a complete optimization like the one for the powers-of-2 regex "(?!(x(xx)+|)\1*$)", but does result in a huge speed improvement.