Title
Description:
Count the number of prime numbers less than a non-negative number, n.
题目大意:计算小于n的素数个数
Solution
//cpp:
class Solution {
public:
int countPrimes(int n) {
int count = 0;
vector<bool> v(n);
fill(v.begin(), v.end(), false);
for (int i = 2; i < n; i++) {
if (v[i])
continue;
count++;
for (int j = i+i; j < n; j += i) {
v[j] = true;
}
}
return count;
}
};