Commit ff67e922 authored by Michael's avatar Michael

michael.davityan:exercise_05_20v7

parent 9ddce7f7
#include <iostream>
#include <algorithm>
int
main()
{
const int SIDE_LENGTH_LIMIT = 500;
for (int hypotenuse = 5; hypotenuse <= SIDE_LENGTH_LIMIT; ++hypotenuse) {
const int hypotenuseSquare = hypotenuse * hypotenuse;
for (int catheter1 = 3; catheter1 < hypotenuse - 1; ++catheter1) {
for (int catheter2 = hypotenuse - 1; (catheter2 > catheter1) && (catheter1 + catheter2 > hypotenuse + 1); --catheter2) {
if (hypotenuse * hypotenuse == catheter1 * catheter1 + catheter2 * catheter2) {
const int catheter1Square = catheter1 * catheter1;
const int CATHETER_LIMIT = std::max(catheter1, hypotenuse-catheter1+1);
for (int catheter2 = hypotenuse - 1; catheter2 > CATHETER_LIMIT; --catheter2) {
const int catheter2Square = catheter2 * catheter2;
if (hypotenuseSquare == catheter1Square + catheter2Square) {
std::cout << hypotenuse << ", " << catheter1 << ", " << catheter2 << std::endl;
}
++count;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment