-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumFourPrimes.cpp
71 lines (60 loc) · 1023 Bytes
/
sumFourPrimes.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
#include <bits/stdc++.h>
#define N 10000000
using namespace std;
//un numero representado por la suma de 4 primos
//https://uva.onlinejudge.org/index.php?option=onlinejud10168 - Summation of Four Primesge&page=show_problem&problem=1109
bool sieve[N];
vector <int> primes;
void criba()
{
memset(sieve, true, sizeof(sieve));
sieve[0] = sieve[1] = false;
for(int i = 2; i <= sqrt(N); i++)
{
if(sieve[i])
{
for (int j = 2; i*j <= N ; j++)
{
sieve[i*j] = false;
}
}
}
}
void goldbach(int n, int *a, int *b)
{
if(n == 4)
{
*a = 2;
*b = 2;
return;
}
for (int i = 3; i <= n/2; i += 2)
{
cout<<i<<endl;
if(sieve[i] && sieve[n-i]){
cout<<"i acepted"<<endl;
*a = i;
*b = n-i;
break;
}
}
}
int main()
{
int n;
int a = 0, b = 0;
criba();
while(cin>>n)
{
if(n <= 7){
cout<<"Impossible."<<endl;
}else if(n%2){
goldbach(n-5, &a, &b);
cout<<"2 3 "<<a<<" "<<b<<endl;
}else{
goldbach(n-4, &a, &b);
cout<<"2 2 "<<a<<" "<<b<<endl;
}
}
return 0;
}