-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathSumOfPrimes.cpp
76 lines (60 loc) · 1.05 KB
/
SumOfPrimes.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
72
73
74
75
76
// N as Sum of Primes
// Given a number N, print "YES" if N can be expressed as a sum of 2 prime numbers and "NO" otherwise.
// Input Format
// One number, N.
// Constraints
// 1 <= N <= 10^5.
// Output Format
// "YES" or "NO"
// Sample Input 0
// 5
// Sample Output 0
// YES
// Explanation 0
// 5 = 2 + 3
// Sample Input 1
// 11
// Sample Output 1
// NO
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int check(int n)
{
int flag=0;
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0||n==1)
return 1;
else
return 0;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin>>n;
int temp=n;
int flag=0;
for(int i=2;i<=n/2;i++)
{
if(check(i)==1&&check(n-i)==1)
{
flag=1;
break;
}
}
if(flag==1)
cout<<"YES";
else
cout<<"NO";
return 0;
}