public static bool[] SieveOfEratosthenes(int num)
{
bool[] isPrime = new bool[num + 1];
for (int i = 2; i <= num; i++) isPrime[i] = true;
// Removing multiples.
for (int i = 2; i <= num; i++)
{
if (isPrime[i])
{
for (int j = i * 2; j <= num; j += i)
isPrime[j] = false; // Eliminate multiples of i.
}
}
return isPrime;
}