class Solution {
public:
int countPrimes(int n) {
vector<bool> arr(n, true);
for (int i = 2; i * i < n; ++i) {
for (int j = i * i; j < n; j += i) {
arr[j] = false;
}
}
int ans = 0;
for (int i = 2; i < n; ++i) {
if (arr[i])
ans++;
}
return ans;
}
};
菜鸡只会埃氏筛
最新推荐文章于 2023-03-31 16:52:02 发布