-
Notifications
You must be signed in to change notification settings - Fork 0
/
es9.cpp
executable file
·41 lines (34 loc) · 915 Bytes
/
es9.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
#include<iostream>
using namespace std;
/*
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.
*/
int F(int sumTriplet){
int a = 0, b = 0, c = 0, sum = 0;
bool found = false;
while(c < sumTriplet && !found){
sum = a + b + c;
if (sum == 1000 && (a*a + b*b == c*c)){
cout << a << endl << b << endl << c << endl << endl;
found = true;
}else{
if (a == sumTriplet){
a = 0;
b++;
}
if (b == sumTriplet){
b = 0;
c++;
}
a++;
}
}
return a*b*c;
}
int main(){
cout << F(1000);
}