Faster without building a large set of primes.
Just use the library function.
Found a way to get the maximum number of terms.