-
Notifications
You must be signed in to change notification settings - Fork 0
/
10948 accepted.cpp
53 lines (50 loc) · 1 KB
/
10948 accepted.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
#include <iostream>
#include <cmath>
#define N 10000000
using namespace std;
int status[N];
int prime[N];
void sieve(){
int p=0;
status[2]=0;
status[1]=1;
status[0]=1;
for(int i=3 ; i<=N ; i+=2)
status[i]=0;
for(int i=4 ; i<=N ; i+=2)
status[i]=1;
for(int i=3 ; i<=sqrt(N) ; i+=2){
if(status[i]==0){
for(int j=i*i ; j<=N ; j+=i+i)
status[j]=1;
}
}
for(int i=0 ; i<=N ; i++){
if(status[i]==0){
prime[p]=i;
p++;
}
}
}
int main()
{
int n,a,b;
sieve();
while(cin>>n && n!=0){
for(int i=0 ; prime[i]<=n ; i++){
int x=n-prime[i];
if(status[x]==0){
a=prime[i];
b=x;
break;
}
else
a=0;
}
if(a==0 || n==1)
cout<<n <<":"<<endl<<"NO WAY!" <<endl;
else
cout<<n <<":"<<endl <<a <<"+" <<b <<endl;
}
return 0;
}