More messing around with primes and exponents (unsurprisingly can't beat BigInt.pow's implementation)