-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path87.cpp
More file actions
59 lines (53 loc) · 1.01 KB
/
Copy path87.cpp
File metadata and controls
59 lines (53 loc) · 1.01 KB
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
58
59
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
using namespace std;
#define MAX 8000
#define LL long long
#define LIMIT 50000000
bool composite[MAX + 1];
vector<int> primes;
set<int> unique; // Can be eliminated if we do careful counting
void seive(int n)
{
int i, j;
for (i = 2; i * i <= n; i++)
{
if (composite[i])
continue;
for (j = 2 * i; j <= n; j += i)
composite[j] = 1;
primes.push_back(i);
}
for (; i <= n; i++)
if (!composite[i])
primes.push_back(i);
}
int main()
{
seive(MAX);
for (int i = 0; i < primes.size(); i++)
{
LL x = primes[i];
if (x * x >= LIMIT)
break;
for (int j = 0; j < primes.size(); j++)
{
LL y = primes[j];
if (x * x + y * y * y >= LIMIT)
break;
for (int k = 0; k < primes.size(); k++)
{
LL z = primes[k];
if (x * x + y * y * y + z * z * z * z >= LIMIT)
break;
unique.insert(x * x + y * y * y + z * z * z * z);
}
}
}
cout << unique.size() << endl;
return 0;
}