Small optimization to is_prime function
Solution for problem 27