I wanted to solve a question from project euleur about finding the largest prime number of a big number. I run my code on a virtual machine on Visual studio 2012, and the code seems froze. When I step into the loop, the code works well, but when I execute it, the console is always there. It is as if the program is still running. Could it be that the program takes time to execute?
My Code
static void Main(string[] args)
{
long number = 5;
for (long i = 1; i < 600851475143; i++)
{
if (i % 2 != 0 && i % 1 == 0 && i % i == 0)
number = i;
}
}
I ran this bit of code and it does take a while to run, but it does seem to progress (i does increment). Try this to determine whether i is a prime:
I can’t claim credit for this. It is from http://www.dotnetperls.com/prime.
Add some Console.WriteLines to your main method to its progress:
There’s other resources out there for these algorithms too:
http://csharpinoneroom.blogspot.com/2008/03/find-prime-numer-at-fastest-speed.html
Good luck!