-
Notifications
You must be signed in to change notification settings - Fork 0
/
584D_DimaandLisa.cc
101 lines (85 loc) · 1.65 KB
/
584D_DimaandLisa.cc
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
*
* Author : fcbruce <fcbruce8964@gmail.com>
*
* Time : Sat 10 Oct 2015 10:15:15 PM CST
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;
typedef long long LL;
typedef int itn;
const int maxn = 10000007;
const int maxm = 0;
bool isp[maxn];
int prime[maxn];
int pn;
inline bool isprime(int x)
{
int limit = sqrt(x);
limit++;
for (int i = 0; prime[i] < limit; i++) if (x % prime[i] == 0) return false;
return true;
}
int main()
{
#ifdef FCBRUCE
//freopen("/home/fcbruce/code/t", "r", stdin);
#endif // FCBRUCE
pn = 0;
memset(isp, true, sizeof isp);
isp[0] = isp[1] = false;
for (int i = 2; i < maxn; i++)
{
if (!isp[i]) continue;
prime[pn++] = i;
for (int j = i + i; j < maxn; j += i) isp[j] = false;
}
int n;
scanf("%d", &n);
int cut = std::lower_bound(prime, prime + pn, n) - prime;
if (prime[cut] == n) printf("1\n%d\n", n);
else
{
cut--;
n -= prime[cut];
if (n == 2)
{
printf("2\n2 %d\n", prime[cut]);
return 0;
}
for (int i = 0; i < pn && prime[i] < n; i++)
{
if (isprime(n - prime[i]))
{
printf("3\n%d %d %d\n", prime[cut], prime[i], n - prime[i]);
return 0;
}
}
}
return 0;
}