Description:
Count the number of prime numbers less than a non-negative number, n.
题解:就是线性筛素数的模板题。
class Solution {
public:
int countPrimes(int n) {
int ans=;
vector<int>is_prime(n+,);
for(int i=;i<n;i++){
if(is_prime[i]){
ans++;
for(int j=*i;j<n;j+=i){
is_prime[j]=;
}
}
}
return ans;
}
};