-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.cpp
More file actions
38 lines (30 loc) · 801 Bytes
/
9.cpp
File metadata and controls
38 lines (30 loc) · 801 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
36
37
38
/*A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a;
for (int i = 1; i < 501; ++i)
{
for (int j = 501-i; j < 1001 - i; ++j)
{
double c =sqrt(i*i + j*j);
if (c == floor(c))
{
int addition = c + i + j;
// cout << "addition = " << addition << endl;
if(addition == 1000)
{
unsigned long long result = i*j*c;
cout << "i = " << i << "; j = " << j << "; c = " << c << endl;
cout << "Result = " << result << endl;
}
}
}
}
}