So this is a fast way to test primality of a number, called a sieve. The PRIMES constant is a list of all the prime numbers below sqrt(1000000000). Computing the values in the sieve actually takes a relatively long time, on the order of seconds; someone cleverer than me could probably make it recursive, such that it would construct itself on the fly, but all of my attempts to do this took much longer than a constant.
Also, protip, don't do expensive calculations like sqrt(n) more than once if you can avoid it. That actually was a huge performance gain, the reason this is an order of magnitude (or more) faster and not just 70% faster.