Now that we have a function for generating primes, the next library function we will need is to check whether a given number is prime.

The basic method for checking whether a given number n is prime is to use trial division. This involves dividing n by the prime integers from 2 to the square root of n. If any of these divisions result in an integer the number n is not prime, else it is prime. (more…)