forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path749A - Bachgold Problem.cpp
54 lines (40 loc) · 1.19 KB
/
749A - Bachgold Problem.cpp
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
/*
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.
Input
The only line of the input contains a single integer n (2?=?n?=?100?000).
Output
The first line of the output contains a single integer k — maximum possible number of primes in representation.
The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.
Examples
inputCopy
5
outputCopy
2
2 3
inputCopy
6
outputCopy
3
2 2 2
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int res;
if (n % 2) {
res = 1 + (n - 3) / 2;
cout << res << endl;
cout << 3 << " ";
for (int i = 1; i <= res - 1; i++) cout << 2 << " ";
} else {
res = n / 2;
cout << res << endl;
for (int i = 1; i <= res; i++) cout << 2 << " ";
}
return 0;
}