Initial commit
This commit is contained in:
33
2022/republic/d0/problem06/try2.cpp
Normal file
33
2022/republic/d0/problem06/try2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
bool areCoprimes(int a, int b, int c) {
|
||||
return __gcd(a, b) == 1 && __gcd(a, c) == 1 && __gcd(b, c) == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
cin >> c;
|
||||
|
||||
uint64_t cSqr = pow(c, 2);
|
||||
bool found = false;
|
||||
for (int a = 1; a <= c; a++) {
|
||||
uint64_t aSqr = pow(a, 2);
|
||||
for (int b = a; b <= c; b++) {
|
||||
if (aSqr + pow(b, 2) == cSqr && areCoprimes(a, b, c)) {
|
||||
cout << a << " " << b << " " << c << endl;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "NOPE" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user