working solution for generating primes from a range