백준2581: 소수
문제
https://www.acmicpc.net/problem/2581
문제 풀이
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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int min = Integer.MAX_VALUE;
int sum = 0;
for (int i = n; i <= m; i++) {
int cnt = 0;
for (int j = 1; j <= i; j++) {
if (i % j == 0) {
cnt++;
}
}
if (cnt == 2) {
sum += i;
if (min > i) {
min = i;
}
}
}
if (sum == 0) {
System.out.println(-1);
} else {
System.out.println(sum+"\n"+min);
}
}
}
댓글남기기