import java.util.Scanner;
public class Main {
public static boolean isPrime(int x) {
int flag=0;
int t = (int) Math.sqrt(x);
for (int i = 2; i <= t; i++) {
if (x % i == 0){
flag=1;
break;
}
}
if(flag==1)
return false;
return true;
}
public static void main(String[] args) {
int a, n, sum = 0;
Scanner in = new Scanner(System.in);
while(in.hasNext()){
sum=0;
n = in.nextInt();
while (n-- != 0) {
a = in.nextInt();
if (isPrime(a)) {
sum++;
}
}
System.out.println(sum);
}
}
}
HDU2.1.2 java 素数个数
最新推荐文章于 2019-06-03 21:13:15 发布