// floriankirsch.de/c++/tripel.html

#include <chrono>
#include <iostream>

int testTripel(int64_t a, int64_t b, int64_t c)
{
    int64_t aabb = a * a + b * b;
    int64_t cc = c * c;
    if (aabb == cc)
        return 0;
    if (aabb < cc)
        return -1;
    return 1;
}

void findTripel1_OneLoop(int64_t c)
{
    int64_t a = 1;
    int64_t b = c - 1;
    while (a < b)
    {
        int result = testTripel(a, b, c);
        if (result == 0)
        {
            std::cout << a << "² + " << b << "² = " << c << "²\n";
            ++a;
        }
        else if (result < 0)
        {
            ++a;
        }
        else
        {
            --b;
        }
    }
}

int main()
{
	std::cout << "Pythagorean tripels found in 1 millisecond\n";
	auto start = std::chrono::steady_clock::now();
	for (int64_t c=1; ; ++c)
	{
	    findTripel1_OneLoop(c);
		auto duration = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start);
		if (duration.count() > 1000)
		    break;
	}
	return 0;
}