-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem9.cpp
More file actions
35 lines (28 loc) · 735 Bytes
/
problem9.cpp
File metadata and controls
35 lines (28 loc) · 735 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
#include <iostream>
#include <cmath>
#include <vector>
struct Triples{
int _a, _b, _c;
Triples(int a, int b, int c) : _a(a), _b(b), _c(c) {}
int sum() {return _a + _b + _c;}
int product() {return _a * _b * _c;}
};
bool pSq(int n, double& sq){
sq = sqrt(n);
return sq == floor(sq);
}
int main(void){
std::vector<Triples> ptgn {};
int prod = 0;
double k;
for(int i = 1; i <= 1000; ++i)
for(int j = 1; i + j <= 1000; ++j)
if(pSq(i*i + j*j, k)){
Triples t {i, j, (int)k};
ptgn.push_back(t);
}
for(auto x : ptgn)
if(x.sum() == 1000) prod = x.product();
std::cout << prod << std::endl;
return 0;
}