refer: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

```
int countPrimes(int n)
{
if (2 >= n) return 0;
bool* primes = new bool[n];
for (int i = 2; i < n; ++i)
primes[i] = true;
int sqr = sqrt(n - 1);
for (int i = 2; i <= sqr; ++i)
{
if (primes[i])
{
for (int j = i + i; j < n; j += i)
primes[j] = false;
}
}
int sum = 0;
for (int i = 2; i < n; ++i)
sum += (primes[i]) ? 1 : 0;
delete[] primes;
return sum;
}
```