```
class Solution {
public:
int countPrimes(int n) {
vector<int>res(n,0);
int cnt = 0;
for(int i = 2; i < n;i++){
if(res[i] == 0){
cnt++;
for(int j = 2; j*i < n;++j){
res[i*j] = 1;
}
}
}
return cnt;
}
};
```