File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments