Sieve of Eratosthenes
class Solution { public: int countPrimes(int n)
{ if(n < 2) return 0;
vector<bool> rec(n + 1, false); int bound = floor(sqrt(n)); int removed = 0; for (int i = 2; i <= bound; i++) { if (!rec[i]) { for (int j = 2*i; j < n; j += i) { if (!rec[j]) { rec[j] = true; removed++; } } } } return n - 2 - removed; } };