-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI013.java
More file actions
49 lines (47 loc) · 1.26 KB
/
I013.java
File metadata and controls
49 lines (47 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package levelB;
import java.util.ArrayList;
import java.util.Scanner;
public class I013 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int M=s.nextInt();
int N=s.nextInt();
ArrayList<Integer> list=new ArrayList<>();
list.add(2);
list.add(3);
int num=5;
int count=2;
if(N>2){
while(count<N){
if(num%6!=1&&num%6!=5){
num++;
continue;
}
boolean flag=true;
for(int i=5;i<=Math.sqrt(num);i+=6){
if(num%i==0||num%(i+2)==0){
flag=false;
break;
}
}
if(flag){
list.add(num);
count++;
}
num++;
}
}
count=0;
for(int i=M-1;i<N;i++){
System.out.print(list.get(i));
count++;
if(count%10==0){
System.out.println();
}else{
if(i!=N-1){
System.out.print(" ");
}
}
}
}
}