passes valgrind and produces primes