forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10948.cpp
62 lines (58 loc) · 814 Bytes
/
10948.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
#include <bits/stdc++.h>
using namespace std;
bool primes[1000001];
void sieve()
{
fill(primes, primes + 1000001, true);
for (int i = 2; i < 1002; i++)
{
for (int j = i * i; j < 1000001; j += i)
{
primes[j] = false;
}
}
primes[0] = primes[1] = false;
}
int main()
{
int n;
sieve();
while (cin >> n)
{
int last;
if (n == 0)
{
break;
}
if (n % 2 == 0)
{
last = n - 1;
}
else
{
last = n - 2;
}
cout << n << ":" << endl;
if (primes[n - 2])
{
cout << 2 << "+" << n - 2 << endl;
continue;
}
bool found = false;
while (n - last <= last)
{
if (primes[last] && primes[n - last])
{
cout << n - last << "+" << last << endl;
found = true;
break;
}
last -= 2;
}
if (!found)
{
cout << "NO WAY!" << endl;
}
}
return 0;
}