Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ksinji/202512/17 BOJ 신기한 소수.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
```java
import java.io.*;
import java.util.*;

public class Main {
static int N;
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());

int[] start = {2, 3, 5, 7};
for (int s : start) dfs(s, 1);

System.out.print(sb);
}

static boolean isPrime(int x) {
if (x < 2) return false;
if (x == 2) return true;
if (x % 2 == 0) return false;
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0) return false;
}
return true;
}

static void dfs(int num, int depth) {
if (depth == N) {
sb.append(num).append('\n');
return;
}
for (int d = 1; d <= 9; d++) {
int next = num * 10 + d;
if (isPrime(next)) dfs(next, depth + 1);
}
}
}
```