令Pi表示第i个素数 现任给两个正整数M <= N <= 10000 请输出PM到PN的所有素数
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().split(" ");
shusushu(Integer.parseInt(str[0]),Integer.parseInt(str[1]));
}
public static void shusushu(int M,int N){
int index=1;
int num[]=new int[N-M+2];
if(M==1) {
num[index]=2;
index++;
}
int count=1;
for(int i=3;index<=N-M+1;i=i+2) {
if(isPrime(i)) {
count++;
if(count>=M) {
num[index]=i;
index++;
}
}
}
for(int i=1;i<N-M+2;i++) {
if(i%10==0) System.out.println(num[i]);
else if(i==N-M+1) System.out.print(num[i]);
else System.out.print(num[i]+" ");
}
}
public static boolean isPrime(int number) {
for(int i=3;i<=Math.sqrt((double)number);i=i+2) {
if(number%i==0) return false;
}
return true;
}
}