LeetCode :Count Primes
Description:
Count the number of prime numbers less than a non-negative number, n.
class Solution {
public:
int countPrimes(int n) {
int count = 0;
int *a = new int[n]();
if(n<2)
return 0;
for(int i=2;i<n;++i){
if(a[i]==0)
{
count++;
for(int j=2;i*j<n;++j){
a[i*j] = 1;
}
}
}
return count;
}
};