-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path46.cpp
More file actions
36 lines (30 loc) · 667 Bytes
/
46.cpp
File metadata and controls
36 lines (30 loc) · 667 Bytes
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
#include <iostream>
#include <cmath>
#include <algorithm>
#include "sieve.h"
inline bool is_integral(double p) {
return std::abs(p - (std::uint64_t) p) < 0.000001;
}
constexpr int limit = 1000000;
const auto s = sieve(limit);
int main() {
std::vector<std::uint64_t> primes;
primes.push_back(2);
for (std::uint64_t i = 3; i <= limit; i += 2) {
if (s[i]) primes.push_back(i);
else {
bool possible = false;
for (auto &p : primes) {
if (is_integral(std::sqrt((i - p) / 2))) {
possible = true;
break;
}
}
if (!possible) {
std::cout << i << std::endl;
return 0;
}
}
}
std::cout << "limit too small" << std::endl;
}