public class Prime {
private static int MAX = 10000000;
private int[] isPrime = new int[MAX];
private void prime(){
for(int i=0;i<MAX;i++){
if(i==0 || i==1){
isPrime[i] = 0;
}else{
isPrime[i] = 1;
}
}
for(int i=2;i*i<MAX;i++){
if(isPrime[i]==1){
for(int j=i;j*i<MAX;j++){
isPrime[j*i] = 0;
}
}
}
}
public static void main(String...args){
Prime p = new Prime();
p.prime();
long start = System.currentTimeMillis();
/*for(int i=0;i<p.isPrime.length;i++){
if(p.isPrime[i]==1){
System.out.println(i+"是质数");
}
}*/
long end = System.currentTimeMillis();
System.out.println(end-start);
}
}
判断素数
最新推荐文章于 2023-07-30 11:02:04 发布