-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem46.cpp
57 lines (50 loc) · 886 Bytes
/
problem46.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
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#define N 1e6
using namespace std;
vector<bool> isPrime(N+1, true);
void sieve()
{
for (int i = 2; i<sqrt(N); i++){
if (!isPrime[i]) continue;
for (int j = i*i; j<=N;j+=i){
isPrime[j] = false;
}
}
}
bool isflint(double x){
return ceil(x) == x;
}
bool isSquare(int x)
{
auto s = sqrt(double(x)*0.5);
if (isflint(s)) return true;
return false;
}
bool writeAsPrimeSum(int n)
{
if (isPrime[n]) return true;
for (int i = 2; i<=n-2;i++){
if (!isPrime[i]){
continue;
}
if (isSquare(n-i)){
return true;
}
}
return false;
}
int main()
{
sieve();
int n = 9;
while(true){
if (!writeAsPrimeSum(n)){
break;
}
n+=2;
}
cout<<n<<endl;
}