#include <iostream> #include <cmath> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); short n; cin >> n; int mozliwosci = 0; for (short przekatna = 1; przekatna <= n; przekatna++) for (short a = 1; a < przekatna; a++) for (short b = a; b < przekatna; b++) { // d = sqrt(a2 + b2 + h2) // d2 = a2 + b2 + h2 // d2 - a2 - b2 = h2 float h2 = (przekatna*przekatna) - (a*a) - (b*b); short h = sqrt(h2); // (int) h * (int) h h2 // (int) h moze byc rowne 0, lecz akwarium nie moze miec 0 if (h * h == h2 && h > 0) mozliwosci++; } cout << mozliwosci << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <iostream> #include <cmath> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); short n; cin >> n; int mozliwosci = 0; for (short przekatna = 1; przekatna <= n; przekatna++) for (short a = 1; a < przekatna; a++) for (short b = a; b < przekatna; b++) { // d = sqrt(a2 + b2 + h2) // d2 = a2 + b2 + h2 // d2 - a2 - b2 = h2 float h2 = (przekatna*przekatna) - (a*a) - (b*b); short h = sqrt(h2); // (int) h * (int) h h2 // (int) h moze byc rowne 0, lecz akwarium nie moze miec 0 if (h * h == h2 && h > 0) mozliwosci++; } cout << mozliwosci << "\n"; } |