public static int countPrimes(int n) {
if (n == 1) return 0;
if (n == 2) return 0;
if (n == 3) return 1;
if (n == 4) return 2;
if (n == 5) return 2;
if (n == 6) return 3;
if (n == 7) return 3;
if (8 <= n && n <= 11) return 4;
if (n > 11) {
int count = 0;
for (int i = 11; i < n; i++) {
//if里面的判断条件是一个数是质数的必要不充分条件
if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) {
count++;
System.out.println(i);
}
}
return count + 4;
}
return 0;
}