Description:
Count the number of prime numbers less than a non-negative number, n.
找出小于n的质数的个数
public class Solution {
public int countPrimes(int n) {
if(n<=2)
return 0;
boolean[] a = new boolean[n];
int count=0;
for(int i=2;i<n;i++)
{
if(!a[i])
{
count++;
for(int j=i;j<n;j+=i)
{
a[j]=true;
}
}
}
return count;
}
}