File tree Expand file tree Collapse file tree 1 file changed +82
-0
lines changed
Expand file tree Collapse file tree 1 file changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.awt.* ;
3+ import java.io.BufferedReader ;
4+ import java.io.IOException ;
5+ import java.io.InputStreamReader ;
6+ import java.util.* ;
7+ import java.util.List ;
8+
9+ public class Main {
10+
11+ static StringBuilder sb = new StringBuilder ();
12+ static int target;
13+ static boolean [] num;
14+
15+ // 골드바흐의 강한 추측: 2보다 큰 짝수는 항상 두 소수의 합으로 표현할 수 있다.
16+ // 골드바흐의 약한 추측: 5보다 큰 홀수는 항상 세 소수의 합으로 표현할 수 있다.
17+ // 8 이상의 짝수는 항상 네 소수의 합으로 표현 가능하다-> 두 소수 + 2 + 2
18+ // 9 이상의 홀수는 항상 네 소수의 합으로 표현 가능하다.-> 세 소수 + 2
19+ // 즉 8이상은 항상 표현이 가능하다.
20+ public static void main (String [] args ) throws IOException {
21+ init();
22+ process();
23+ print();
24+ }
25+
26+ private static void init () throws IOException {
27+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
28+ target = Integer . parseInt(br. readLine());
29+ num = new boolean [target + 1 ];
30+ Arrays . fill(num, true );
31+ num[0 ] = false ;
32+ num[1 ] = false ;
33+ }
34+
35+ private static void process () {
36+ if (target < 8 ) {
37+ sb. append(- 1 );
38+ return ;
39+ }
40+
41+ getPrimes();
42+ int curNum = target;
43+ if ( target % 2 == 0 ){
44+ sb. append(" 2 2 " );
45+ curNum -= 4 ;
46+ } else {
47+ sb. append(" 2 3 " );
48+ curNum -= 5 ;
49+ }
50+
51+ for (int i = 2 ; i <= curNum/ 2 ; i++ ) {
52+ if (num[i] && num[ curNum - i]) {
53+ sb. append(i). append(" " ). append(curNum- i);
54+ return ;
55+ }
56+ }
57+ }
58+
59+ private static void getPrimes () {
60+ for (int i = 2 ; i * i <= target; i++ ) {
61+ if (num[i]) {
62+ int temp = i* 2 ;
63+ while ( temp <= target ) {
64+ num[temp] = false ;
65+ temp += i;
66+ }
67+ }
68+
69+ }
70+ }
71+
72+
73+ private static void print () {
74+ System . out. println(sb. toString());
75+ }
76+
77+
78+
79+ }
80+
81+
82+ ```
You can’t perform that action at this time.
0 commit comments