public static bool TestPrime(int x)
{
if ((x & 1) != 0)
{
int top = (int)Math.Sqrt(x);
for (int n = 3; n < top; n += 2)
{
if ((x % n) == 0)
return false;
}
return true;
}
// There is only one even prime - 2.
return (x == 2);
}