class Solution {
public:
int countPrimes(int n) {
int ans = 0;
vector <bool> is(n, true);
for (int i = 2; i < n; i++) {
if (is[i]) {
ans++;
for (int j = i + i; j < n; j += i) {
is[j] = false;
}
}
}
return ans;
}
};