Description:
Count the number of prime numbers less than a non-negative number, n.
class Solution {
public:
int countPrimes(int n) {
bool get[n];
memset(get, false, sizeof(get));
int count = 0;
for(int i=2; i*i<n; i++)
{
if(!get[i])
{
for(int j=i; j*i<n; j++)
{
get[i*j] = true;
}
}
}
for(int i=2; i<n; i++)
if(get[i] == false)
count++;
return count;
}
};