#include // MS VC++ /await /std=c++latest #include #include #include using Triple = std::tuple; using namespace std::experimental; generator pythagorean_triples(int limit) { for (auto z = 1; z < limit; ++z) for (auto y = 1; y < z; ++y) for (auto x = 1; x < y; ++x) if (x * x + y * y == z * z) { std::cout << '\t' << x << ' ' << y << ' ' << z << '\n'; co_yield {x, y, z}; } } generator irreducible_pythagorean_triples(int limit) { for (auto [x, y, z] : pythagorean_triples(limit)) if (std::gcd(x, z) == 1 && std::gcd(y, z) == 1) co_yield {x, y, z}; } int main() { std::cout << "\tpythagorean triple\nirreducible\n"; for (auto [x, y, z] : irreducible_pythagorean_triples(30)) std::cout << x << ' ' << y << ' ' << z << '\n'; }