Skip to content

Commit c84f50d

Browse files
authored
[20260219] BOJ / G5 / 신기한 소수 / 이인희
1 parent e791ae0 commit c84f50d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
public class Main {
7+
static int N;
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
N = Integer.parseInt(br.readLine());
11+
//1자리 소수로 모두 시작
12+
startTo(1, 2, N);
13+
startTo(1, 3, N);
14+
startTo(1, 5, N);
15+
startTo(1, 7, N);
16+
}
17+
18+
private static void startTo(int depth, int value, int n) {
19+
if (!isPrime(value)) {
20+
return;
21+
}
22+
if (depth == n) {
23+
System.out.println(value);
24+
return;
25+
}
26+
27+
28+
for (int digit = 1; digit <= 9; digit++) {
29+
int next = value * 10 + digit;
30+
startTo(depth + 1, next, n);
31+
}
32+
}
33+
34+
private static boolean isPrime(int num) {
35+
if (num < 2) {
36+
return false;
37+
}
38+
for (int i = 2; i * i <= num; i++) {
39+
if (num % i == 0) {
40+
return false;
41+
}
42+
}
43+
return true;
44+
}
45+
}
46+
47+
```

0 commit comments

Comments
 (0)