modified the fast_prime function