1
+ // http://codeforces.com/contest/584/problem/D
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+ #define __ ios_base::sync_with_stdio (0 ); cin.tie(0 );
6
+ #define endl ' \n '
7
+ #define foreach (it, x ) for (__typeof (x).begin() it = (x).begin(); it != (x).end(); ++it)
8
+ #define all (x ) x.begin(),x.end()
9
+ #define D (x ) cout << #x " = " << (x) << endl;
10
+
11
+ template <class T > string toStr (const T &x)
12
+ { stringstream s; s << x; return s.str (); }
13
+
14
+ template <class T > int toInt (const T &x)
15
+ { stringstream s; s << x; int r; s >> r; return r; }
16
+
17
+ int dx[8 ] = {-1 ,-1 ,-1 ,0 ,1 ,1 , 1 , 0 };
18
+ int dy[8 ] = {-1 , 0 , 1 ,1 ,1 ,0 ,-1 ,-1 };
19
+
20
+ vector<int > primes;
21
+
22
+ void gen_primes (int lim) {
23
+ primes.push_back (2 );
24
+
25
+ for (int p = 3 ; p <= lim; p += 2 ) {
26
+ int i = 2 ;
27
+ int f = true ;
28
+ while (i * i <= p) {
29
+ if (p % i == 0 ) {
30
+ f = false ;
31
+ break ;
32
+ }
33
+ i ++;
34
+ }
35
+
36
+ if (f) primes.push_back (p);
37
+ }
38
+ }
39
+
40
+ bool is_prime (int n) {
41
+ if (n < 2 ) return false ;
42
+ if (n == 2 ) return true ;
43
+ int i = 2 ;
44
+ while (i * i <= n) {
45
+ if (n % i == 0 ) return false ;
46
+ i ++;
47
+ }
48
+ return true ;
49
+ }
50
+
51
+ int main () {
52
+ int mx = 1e6 ;
53
+ gen_primes (mx);
54
+
55
+ int n;
56
+ cin >> n;
57
+
58
+ int n2 = n;
59
+ int tmp = n;
60
+
61
+ while (n2 > 0 ) {
62
+ if (!is_prime (n2)) {
63
+ n2 --;
64
+ continue ;
65
+ }
66
+
67
+ n = tmp;
68
+ int f = false ;
69
+ vector<int > ans;
70
+ ans.push_back (n2);
71
+ n -= n2;
72
+
73
+ if (!n) f = true ;
74
+
75
+ for (int i = 0 ; n > 0 && i < primes.size (); ++i) {
76
+ if (primes[i] <= n) {
77
+ int rest = n - primes[i];
78
+ if (rest == 0 ) {
79
+ ans.push_back (primes[i]);
80
+ f = true ;
81
+ break ;
82
+ }
83
+ if (is_prime (rest)) {
84
+ ans.push_back (primes[i]);
85
+ ans.push_back (rest);
86
+ f = true ;
87
+ break ;
88
+ }
89
+ }
90
+ else break ;
91
+ }
92
+
93
+ if (f) {
94
+ cout << ans.size () << endl;
95
+ for (int i = 0 ; i < ans.size (); ++i) cout << ans[i] << " " ;
96
+ return 0 ;
97
+ }
98
+ n2 --;
99
+ }
100
+
101
+ return 0 ;
102
+ }
0 commit comments