#include #include #include #include #include #include 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() { int64_t c; cin >> c; map roots; int64_t i = 1; while (true) { int64_t tmp = pow(i, 2); if (tmp > c) { break; } roots[tmp] = i; i++; } int64_t rightLimit = i - 1; set> results; for (int64_t x = 1; x <= rightLimit; x++) { int64_t xSqr = pow(x, 2); int64_t y = roots[c - xSqr]; if (y == 0) { continue; } // x^4 + 2*x^2*y^2 + y^4 = r^2 // x^4 - 2*x^2*y^2 + y^4 + 4*x^2*y^2 = r^2 // (x^2-y^2)^2 + (2*x*y)^2 = r^2 // a = x^2-y^2 b = 2*x*y int64_t a = pow(y, 2) - pow(x, 2); int64_t b = 2 * x * y; if (a > b) { swap(a, b); } if (a < 0) { continue; } if (areCoprimes(a, b, c)) { results.insert(make_pair(a, b)); } } if (results.size() == 0) { cout << "NOPE" << endl; } else { for (auto it = results.begin(); it != results.end(); it++) { cout << (it -> first) << " " << (it -> second) << " " << c << endl; } } return 0; }