题目链接:https://www.nowcoder.com/pat/6/problem/4079
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int m,n;
int t;
int p;
int cnt,ccnt;
boolean bool;
while(cin.hasNext()){
m=cin.nextInt();
n=cin.nextInt();
p=0;
cnt=2;ccnt=0;
if(m==1){
cnt=0;
System.out.print(2);
cnt++;ccnt++;
if(n==1){
break;
}
System.out.print(" ");
System.out.print(3);
cnt++;ccnt++;
if(n==2){
break;
}
p=1;
}
if(m==2){
cnt=1;
System.out.print(3);
cnt++;ccnt++;
if(n==2){
break;
}
p=1;
}
for(int i=5;cnt<=n-1;i++){
t=i/2;
bool=false;
for(int j=2;j<=t;j++){
if(i%j==0){
bool=false;
break;
}
if(j==t){
bool=true;
}
}
if(bool==true){
if(p==1){
System.out.print(" ");
}
cnt++;
if(cnt>=m){
System.out.print(i);
p=1;
ccnt++;
}
if(ccnt>0&&ccnt%10==0){
System.out.println();
p=0;
}
}
}
break;
}
}
}
觉得有帮助,别忘点赞哦!