-
Notifications
You must be signed in to change notification settings - Fork 0
/
The primary problem.cpp
59 lines (55 loc) · 1023 Bytes
/
The primary 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
55
56
57
58
59
#include<iostream>
#include<cmath>
using namespace std;
int is_prime(int a)
{
if(a==2)
return 1;
else if(a%2==0)
return 0;
int x=a/2;
for(int i=3;i<=x;i+=2)
{
if(a%i==0)
{
return 0;
break;
}
}
return 1;
}
int main()
{
unsigned long n,x;
while(cin>>n)
{
if(n==0)
break;
x=1;
if(is_prime(n-2))
{
cout<<n<<":\n";
cout<<2<<'+'<<n-2;
x=0;
}
if(x)
{
for(int i=3;i<=n/2;i+=2)
{
if(is_prime(i) && is_prime(n-i))
{
cout<<n<<":\n";
cout<<i<<'+'<<n-i<<endl;
x=0;
break;
}
}
}
if(x)
{
cout<<n<<":\n";
cout<<"NO WAY!\n";
}
}
return 0;
}