A better implementation will only check to sqrt(n), as there can be no prime factor greater than that without there also being a prime factor lower than that.