-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-101.cpp
35 lines (35 loc) · 874 Bytes
/
Day-101.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
#include <bits/stdc++.h>
using namespace std;
class Solution{
vector<bool>isPrime;
void sieve(int n){
isPrime.assign(n+2 , true);
isPrime[0] = isPrime[1] = false;
for(int i=2;i<=n/2;++i){
if(isPrime[i]){
for(int j=i*i;j<=n;j+=i){
isPrime[j]=false;
}
}
}
return;
}
public:
vector<int>primeNumber(int n){
sieve(n);
for(int i=2;i<=n;++i){
if(isPrime[i] && n-i>0 && isPrime[n-i]){
return {i,n-i};
}
}
assert(false);
}
};
int main(void){
Solution s1;
vector<int> v = s1.primeNumber(4);
cout << v[0] <<" "<< v[1] << '\n';
vector<int> i = s1.primeNumber(99);
cout << i[0] <<" "<< i[1] << '\n';
return 0;
}