-
Notifications
You must be signed in to change notification settings - Fork 0
/
reading line in c++
81 lines (68 loc) · 1.28 KB
/
reading line in c++
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
#include <bits/stdc++.h>
typedef long long ll;
# define FAST_CODE ios_base::sync_with_stdio(false); cin.tie(NULL);
# define pb push_back
using namespace std;
const ll n = 10000001;
vector <ll> Prime;
bool is_composite[n];
bool is_prime[n];
void linear_sieve ()
{
std::fill (is_composite, is_composite + n, false);
for (ll i = 2; i < n; ++i)
{
if (!is_composite[i])
{
Prime.push_back (i);
is_prime[i] = true;
}
for (ll j = 0; j < Prime.size () && i * Prime[j] < n; ++j)
{
is_composite[i * Prime[j]] = true;
if (i % Prime[j] == 0) break;
}
}
}
int main()
{
FAST_CODE
/*
you have to read integrs on each line and you have to tell weather they can expressed as a summation of 4 primes
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1109
summation of four primes UVA
*/
linear_sieve();
string s;
while(getline(cin, s))
{
stringstream geek(s);
ll x;
geek>>x;
// cout<<x<<endl;
if(x<8)
{
cout<<"Impossible."<<endl;
continue;
}
if(x%2==0)
{
x-=4;
cout<<2<<" "<<2<<" ";
}
else if(x%2!=0)
{
x-=5;
cout<<2<<" "<<3<<" ";
}
for(ll i=2; i<=x/2; i++)
{
if(is_prime[i] && is_prime[x-i])
{
cout<<i<<" "<<x-i<<endl;
break;
}
}
}
return 0;
}