We choose k = 40, which is a reasonable value; you could choose something different or make it a parameter if you wish. Note that there is no need to explicitly compute gcd(a, n), as the Jacobi symbol will be zero in that case. The version on the ERH is similar, except that we loop over primes instead of counting down k: