LeetCode: Count Primes(计算n以内素数个数:高效算法)
Description:
Count the number of prime numbers less than a non-negative number, n.
A prime number is a natural number that has exactly two distinct natural number divisors: 1 and itself.
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Algorithm_complexity
埃拉托色尼筛选法:Sieve of Eratosthenes。
时间复杂度:O(n log log n)。
下面是图示过程,还有leetcode上hint用java编写的。
class Solution {
public:
int