So this is problem 3 from project Euler. For those who don\'t know, I have to find out the largest prime factor of 600851475143. I have the below code:
impor
change
for(long i = 2; i <= limit; i++)
to
// add the one for rounding errors in the sqrt function
new_limit = sqrt(limit) + 1;
// all even numbers are not prime
for(long i = 3; i <= new_limit; i+=2)
{
...
}
Factoring 1,000,000 for example instead of iterating 1,000,000 times the thing only needs to do around 500 iterations.