문제
I.O
코드 및 해석
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Boj_2581 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int M = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
int sum = 0;
int min = N;
while(M <= N) {
int n = 1;
int cnt = 0;
while(n <= M) {
if(M % n == 0) cnt++;
n++;
}
if(cnt == 2) {
sum += M;
if(min >= M) min = M;
}
M++;
}
if(sum == 0) {
System.out.println(-1);
return;
}
System.out.println(sum);
System.out.println(min);
}
}
문제 및 사진출처
출처 - 백준 알고리즘_2581번