Why is pow(a, d, n) so much faster than a**d % n?
Why is pow(a, d, n) so much faster than a**d % n? Question: I was trying to implement a Miller-Rabin primality test, and was puzzled why it was taking so long (> 20 seconds) for midsize numbers (~7 digits). I eventually found the following line of code to be the source of the problem: x …