质数——用已有质数求质数

import java.util.*;
public class PrimeNumberUltimate{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Input Limitation:");
int x,i,n=0,m=sc.nextInt(),a[]=new int[m];a[0]=2;
for (x=2;x<=m;x++){
for (i=0;a[i]<=Math.sqrt(x);i++){
if (x%a[i]==0)break;
}
if (a[i]>Math.sqrt(x)){
System.out.print(x+" ");a[n]=x;n++;
if (n%20==0)System.out.println("");
}
}
}
}

posted @ 2017-04-29 14:12  风少凌云  阅读(165)  评论(0编辑  收藏  举报