-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
37 lines (33 loc) · 933 Bytes
/
Main.java
File metadata and controls
37 lines (33 loc) · 933 Bytes
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
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
private static int N;
public static StringBuilder sb;
public static void main(String[] args) {
sb = new StringBuilder();
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
backTracking("");
System.out.println(sb.toString());
}
private static void backTracking(String now){
if(now.length() == N){
sb.append(now).append('\n');
return;
}
for(int i = 0; i < 10; i ++){
if(isPrime(Integer.parseInt(now + i))){
backTracking(now + i);
}
}
}
private static boolean isPrime(int x){
if(x <= 1) return false;
int end = (int) Math.sqrt(x);
for(int i = 2; i <= end; i ++){
if(x % i == 0) return false;
}
return true;
}
}