I am having a problem where my program executes and then just hangs somewhere during execution. I basically want to know what causes this.
for (long i = maxNumber; i > 2; i--)
{
IsPrime = true;
for (long g = 2; g < i; g++)
{
long temp = i % g;
if (temp == 0)
{
IsPrime = false;
break;
}
}
if (IsPrime == true)
{
largestPrimeFactor = i;
break;
}
}
If I tried it correctly, your code is trying to find the largest prime between 0 and maxNumber. Use the Sieve of Eratosthenes for finding all prime numbers between 0 and the square root of maxNumber. Then, you can iterate from maxNumber to 0 for a number indivisible by all of the prime numbers you’ve just found.
EDIT :
Tried this
and it find maxPrime in less than 3 seconds for maxNumber = 600881475134 (the parallelization was because I thought it would take long time)