-
Notifications
You must be signed in to change notification settings - Fork 0
/
day11.cpp
49 lines (45 loc) · 984 Bytes
/
day11.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
#include <bits/stdc++.h>
using namespace std;
vector<int> SieveOfEratosthenes(int n)
{
vector<bool> prime(n + 1, true);
vector<int> primeNo;
for (int p = 2; p * p <= n; p++)
if (prime[p] == true)
for (int i = p * 2; i <= n; i += p)
prime[i] = false;
for (int p = 2; p <= n; p++)
{
if (prime[p])
primeNo.push_back(p);
}
return primeNo;
}
string isSumOfTwo(int N)
{
// code here
int flag = 0;
string yes = "Yes";
string no = "No";
vector<int> prime = SieveOfEratosthenes(N);
for (int i = 0; int j = prime.size() - 1; i < j)
{
int sum = prime[i] + prime[j];
if (sum == N)
{
flag = 1;
break;
}
if (sum < N)
i++;
j++;
}
if (flag == 0)
return no;
return yes;
}
int main(){
string str=isSumOfTwo(17);
cout<<str;
return 0;
}