原题出处:https://leetcode.cn/leetbook/read/top-interview-questions-easy/xnzlu6/
解法一:
class Solution {
public int countPrimes(int n) {
boolean[] bool = new boolean[n];
int result = 0;
for (int i = 2; i < n; i++) {
if (bool[i]) {
continue;
}
result ++;
for (int j = i ; j < n; j += i) {
bool[j] = true;
}
}
return result;
}
}
思路:埃氏筛
枚举 < 埃氏筛 < 欧式筛(线性筛) < 奇数筛