-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_2581.java
More file actions
54 lines (49 loc) ยท 1.08 KB
/
_2581.java
File metadata and controls
54 lines (49 loc) ยท 1.08 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
50
51
52
53
54
package backjoon;
// https://www.acmicpc.net/problem/2581
// ์์
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _2581 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//sol memory 11492 run 84
int M = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
int sum = 0;
int min = 10001;// ๋ฌธ์ ์ ์ฃผ์ด์ง
int minCnt = 0;
for (int i = M; i <= N; i++) {
int j;
for (j = 2; j < Math.sqrt(N); j++) {
// ์์๊ฐ ์๋๋
if (i % j == 0) {
break;
}
}
// ์์์ผ๋
if (j * j > i && i != 1) {
sum += i;
// ๊ฐ์ฅ ์ฒซ๋ฒ์งธ ์์๊ฐ ์ต์๊ฐ์ด ๋๋ค.
if (minCnt == 0) {
min = i;
}
minCnt++;
}
}
if (minCnt == 0) {
System.out.println(-1);
} else {
System.out.println(sum);
System.out.println(min);
}
}
}
/*
input
60
100
output
620
61
*/