So we use the [Miller-Rabin primality test](https://en.wikipedia.org/wiki/Miller-Rabin_primality_test) that I implemented a while ago (thanks [mathblog.dk](https://web.archive.org/web/20150314052138/http://www.mathblog.dk/project-euler-58-primes-diagonals-spiral/)).