File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ package fisa_cote .august ;
2+
3+ import java .util .*;
4+ import java .io .*;
5+
6+ public class Boj2023 {
7+
8+ static int N , count ;
9+ static double digits ;
10+ static int [] sosu = {2 , 3 , 5 , 7 };
11+ static int [] plus = {1 , 3 , 7 , 9 };
12+ static StringBuilder sb = new StringBuilder ();
13+
14+
15+ public static void main (String [] args ) throws IOException {
16+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
17+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
18+
19+ N = Integer .parseInt (br .readLine ());
20+
21+ digits = Math .pow (10 , N );
22+
23+ for (int i = 0 ; i < 4 ; i ++) {
24+ count = 1 ;
25+ dfs (sosu [i ],1 );
26+ }
27+ bw .write (sb .toString ());
28+ bw .flush ();
29+ bw .close ();
30+ br .close ();
31+ }
32+
33+
34+ private static void dfs (int num , int count ) {
35+ if (check (num )) {
36+ if (count == N ) {
37+ sb .append (num ).append ("\n " );
38+ return ;
39+ }
40+ for (int i = 0 ; i < 4 ; i ++) {
41+ dfs (10 *num +plus [i ], count +1 );
42+ }
43+ }else {
44+ return ;
45+ }
46+ }
47+
48+ private static boolean check (int num ) {
49+ int devide = 2 ;
50+ while (devide *devide <= num ) {
51+ if (num % devide == 0 ) {
52+ return false ;
53+ }
54+ devide ++;
55+ }
56+ return true ;
57+ }
58+ }
You can’t perform that action at this time.
0 commit comments