-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler_60.cpp
65 lines (53 loc) · 1.81 KB
/
Euler_60.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
58
59
60
61
62
63
64
65
#include <algorithm>
#include <unordered_set>
#include "Euler.h"
int Euler::PrimePairSets()
{
std::vector<int> primes = EulerUtility::getPrimesUnderCeiling(100000);
std::vector<std::vector<int>> concatPrimes(10000, std::vector<int>());
for (int i = 0; i < 10000; ++i)
{
if (EulerUtility::isPrime(i, 5))
{
for (int p : primes)
{
if (p < i)
{
std::vector<int> concat(1, i);
concat.push_back(p);
int c = EulerUtility::digitsToInteger(concat);
if (EulerUtility::isPrime(c, 5))
{
std::swap(concat[0], concat[1]);
c = EulerUtility::digitsToInteger(concat);
if (EulerUtility::isPrime(c, 5))
{
concatPrimes[i].push_back(p);
concatPrimes[p].push_back(i);
}
}
}
else
break;
}
}
}
for (int i = 0; i < 10000; ++i)
{
for (int j : concatPrimes[i])
{
std::vector<int> intersection_a = EulerUtility::intersect(concatPrimes[i], concatPrimes[j]);
for (int k : intersection_a)
{
std::vector<int> intersection_b = EulerUtility::intersect(intersection_a, concatPrimes[k]);
for (int l : intersection_b)
{
std::vector<int> intersection_c = EulerUtility::intersect(intersection_b, concatPrimes[l]);
if (intersection_c.size() > 0)
return i + j + k + l + intersection_c[0];
}
}
}
}
return 0;
}