Description:
Count the number of prime numbers less than a non-negative number, n.
就是求小于非负整数n的质素的个数(质数:只能被自己和1整除的整数)。
public int countPrimes(int n) {
if(n==0)
return 0;
if(n==1)
return 0;
int count=0;
boolean[] notPrime=new boolean[n];
for(int i=2;i<n;i++){
if(notPrime[i]==false)
count++;
for(int j=2;i*j<n;j++){
notPrime[i*j]=true;
}
}
return count;
}