+ # Use this if you're only testing a few primes and not needing to generate many more.
+ def is_prime?(n)
+ return true if n == 2
+ return false if n < 2
+ limit = Math.sqrt(n).floor
+ while @primes.last <= limit
+ add_next_prime!
+ end
+ index = @primes.bsearch_index {|i| i > limit} || @primes.length
+ @primes[0..index].none? {|i| n % i == 0}
+ end
+