-
Notifications
You must be signed in to change notification settings - Fork 0
/
87.cpp
49 lines (45 loc) · 1.05 KB
/
87.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 <iostream>
#include <vector>
#include <cmath>
#include <unordered_set>
#include "utils.h"
#include "sieve.h"
constexpr int limit = 50'000'000;
int limit_sq = std::sqrt(limit);
const auto s = sieve(limit_sq);
int main() {
std::vector<int> sq, qu, fo;
for (int i = 2; i < s.size(); ++i) {
if (!s[i]) continue;
sq.push_back(i * i);
}
for (int i = 2; i < s.size(); ++i) {
if (!s[i]) continue;
auto res = i * i * i;
if (res >= limit) break;
qu.push_back(res);
}
for (int i = 2; i < s.size(); ++i) {
if (!s[i]) continue;
auto res = i * i * i * i;
if (res >= limit) break;
fo.push_back(res);
}
// std::cout << sq.size() << " " << qu.size() << " " << fo.size() << std::endl;
// print_vector(fo);
std::unordered_set<int> set;
for (auto &x : sq) {
// std::cout << x << std::endl;
for (auto &y : qu) {
const auto xy = x + y;
if (xy >= limit) break;
for (auto &z : fo) {
auto xyz = xy + z;
if (xyz >= limit) break;
// std::cout << res << std::endl;
set.insert(xyz);
}
}
}
std::cout << set.size() << std::endl;
}