Math
Prime Numbers
Sieve of Eratosthenes
| |
204. Count Primes
p[i] represents the number of primes less than or equal to i. Starting from i=2, p[i]==0 <=> i is prime. Then, starting from ii, mark multiples of i as composite (by setting p[ik]=-1). And, p[i] is assigned p[i-1]+1.
If p[i]<0, then i is composite, p[i]=p[i-1].