Count the number of prime numbers less than a non-negative number, n.
Example:
Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
int countPrimes(int n) {
if(n<=2)
return 0;
int i,j,k,t=0;
for(i=2;i<n;i++)
{
k=sqrt(i);
for(j=2;j<=k;j++)
{
if(i%j==0)
break;
}
if(j==k+1)
t++;
}
return t;
}