-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththree_numbers_square.cpp
69 lines (51 loc) · 1.27 KB
/
three_numbers_square.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
66
67
68
69
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iterator>
using namespace std;
const int MAX_RANGE = 250;
int main(int argc, char* argv[]) {
set<int> set_of_integers;
set<int> result;
vector<int> solution_set;
bool flag;
int max_poss_num;
for(int number =0; number < MAX_RANGE; number ++) {
max_poss_num = (int)ceil(pow(number, 0.5));
for (int i =0; i <= max_poss_num; i++) {
for (int j = i; j <= max_poss_num; j++) {
for( int k =j; k <= max_poss_num; k++) {
if( number == pow(i,2.0) + pow(j,2.0) + pow(k,2.0)) {
set_of_integers.insert(number);
flag = true;
break;
}
}
if (flag) {
break;
}
}
if (flag) {
break;
}
}
if (flag) {
flag = false;
}
}
// let's have a set that contains the elements
set<int> full_range;
for (int i =0; i < MAX_RANGE; i++) {
full_range.insert(i);
}
// let's compute the set difference
std::set_difference(full_range.begin(), full_range.end(), set_of_integers.begin(), set_of_integers.end(), std::inserter(result, result.end()));
std::cout << "myset contains:";
for (std::set<int>::iterator it = result.begin(); it !=result.end(); it++) {
std::cout << ' ' << *it;
}
std::cout << '\n';
return 0;
}