calculate primes

Added a function for calculating prime numbers, and implemented the
caching of the primes.