-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2581.java
More file actions
39 lines (33 loc) · 983 Bytes
/
2581.java
File metadata and controls
39 lines (33 loc) · 983 Bytes
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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int m = Integer.parseInt(br.readLine());
int n = Integer.parseInt(br.readLine());
int prime[] = new int[10001];
prime[1]=1; // 1이면 소수가 아님
for(int i=2; i<=Math.sqrt(10000); i++){
if(prime[i]!=1){
for(int j=i*2; j<=10000; j+=i){
prime[j]=1;
}
}
}
int sum=0;
int min=0;
Boolean flag=false;
for(int i=m; i<=n; i++){
if(prime[i]==0){
flag=true;
if(min==0) min=i;
sum+=i;
}
}
if(flag){
System.out.println(sum);
System.out.println(min);
}
else System.out.println(-1);
}
}