-
Notifications
You must be signed in to change notification settings - Fork 0
/
summation_four_primes.cpp
82 lines (69 loc) · 1.77 KB
/
summation_four_primes.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
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
/*
Made by: Romeu I. L. Pires
for "Special topics in programming" course
in UFRJ (Universidade Federal do Rio de Janeiro),
on 2019.1 semester
- Problem PDF:
https://uva.onlinejudge.org/external/101/10168.pdf
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <math.h>
#include <vector>
#define CRIVO_SIZE 10000000
using namespace std;
vector<int> crivo;
vector<int> primes;
void fillCrivo(){
crivo.clear();crivo.resize(CRIVO_SIZE);
crivo[0] = 1;
for( size_t i = 0 ; i < CRIVO_SIZE ; i++ ){
if( crivo[i] == 0 ){
primes.push_back(i+1);
for( size_t j = i + (i+1) ; j < CRIVO_SIZE ; j += (i+1) ){
crivo[j] = 1;
}
}
}
}
pair<int,int> conjectureGoldbach( int N ){
for( auto p : primes ){
if( crivo[N-p-1] == 0 ){
return pair<int,int>( p , N-p );
}
}
}
int main(){
#ifndef ONLINE_JUDGE
ifstream cin("entrada.txt");
ofstream cout("saida.txt");
#endif
// ==========
fillCrivo();
int N;
vector<int> parts;
pair<int,int> last_parts;
while( cin >> N ){
if( N < 8 )
cout << "Impossible." << endl;
else {
parts.clear();
if( N%2==0 ){
parts.push_back(2);
N-=2;
}
else{
parts.push_back(3);
N-=3;
}
parts.push_back(2);
N-=2;
last_parts = conjectureGoldbach(N);
parts.push_back(last_parts.first);
parts.push_back(last_parts.second);
cout << parts[0] << " " <<parts[0] << " " << parts[0] << " " << parts[0] << endl;
}
}
}