#include <cmath>
#include <iostream>
void triples()
{
unsigned found = 0;
unsigned tests = 0;
for (unsigned a = 3; a < 99; ++a)
{
// only interested in a hypotenuse <= 100
const unsigned b_limit = std::sqrt(100*100 - (a*a));
for (unsigned b = a + 1; b <= b_limit; b += 1)
{
++tests;
double c = std::sqrt(a*a + b*b);
if (c == int(c))
{
++found;
std::cout << a << '\t' << b << '\t' << c << '\n';
}
}
}
std::cout << "Triples found: " << found << '\n';
std::cout << "Possibilities tested: " << tests << '\n';
}
int main()
{
triples();
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9zdHJlYW0+CgoKdm9pZCB0cmlwbGVzKCkKewogICAgdW5zaWduZWQgZm91bmQgPSAwOwogICAgdW5zaWduZWQgdGVzdHMgPSAwOwogICAgZm9yICh1bnNpZ25lZCBhID0gMzsgYSA8IDk5OyArK2EpCiAgICB7CiAgICAgICAgLy8gb25seSBpbnRlcmVzdGVkIGluIGEgaHlwb3RlbnVzZSA8PSAxMDAKICAgICAgICBjb25zdCB1bnNpZ25lZCBiX2xpbWl0ID0gc3RkOjpzcXJ0KDEwMCoxMDAgLSAoYSphKSk7CgogICAgICAgIGZvciAodW5zaWduZWQgYiA9IGEgKyAxOyBiIDw9IGJfbGltaXQ7IGIgKz0gMSkKICAgICAgICB7CiAgICAgICAgICAgICsrdGVzdHM7CiAgICAgICAgICAgIGRvdWJsZSBjID0gc3RkOjpzcXJ0KGEqYSArIGIqYik7CgogICAgICAgICAgICBpZiAoYyA9PSBpbnQoYykpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICsrZm91bmQ7CiAgICAgICAgICAgICAgICBzdGQ6OmNvdXQgPDwgYSA8PCAnXHQnIDw8IGIgPDwgJ1x0JyA8PCBjIDw8ICdcbic7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBzdGQ6OmNvdXQgPDwgIlRyaXBsZXMgZm91bmQ6ICIgPDwgZm91bmQgPDwgJ1xuJzsKICAgIHN0ZDo6Y291dCA8PCAiUG9zc2liaWxpdGllcyB0ZXN0ZWQ6ICIgPDwgdGVzdHMgPDwgJ1xuJzsKfQoKCmludCBtYWluKCkKewogICAgdHJpcGxlcygpOwp9Cg==