-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1582.cpp
More file actions
52 lines (42 loc) · 1.06 KB
/
1582.cpp
File metadata and controls
52 lines (42 loc) · 1.06 KB
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
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
void verifyPitagoras(int x, int y, int z) {
int hipotenusa = max(max(x, y), z);
int cat1, cat2;
if(hipotenusa > x && hipotenusa > y) {
cat1 = x;
cat2 = y;
} else if (hipotenusa > y && hipotenusa > z) {
cat1 = y;
cat2 = z;
} else {
cat1 = x;
cat2 = z;
}
if (pow(hipotenusa, 2) == (pow(cat1, 2) + pow(cat2, 2))) {
int maiorCateto = max(cat1, cat2);
int menorCateto = min(cat1, cat2);
int g1 = gcd(hipotenusa, menorCateto);
int g2 = gcd(max(g1, maiorCateto), min(g1, maiorCateto));
if (g2 == 1) {
cout << "tripla pitagorica primitiva" << endl;
return;
}
cout << "tripla pitagorica" << endl;
return;
}
cout << "tripla" << endl;
return;
}
int main() {
int x, y, z;
while(cin >> x >> y >> z) {
verifyPitagoras(x, y, z);
}
return 0;
}