#include <iostream> #include <cmath> #include <set> #include <tuple> using namespace std; int main() { int n; cin >> n; set<tuple<int, int, int>> unique_aquariums; for (int a = 1; a <= n; ++a) { for (int b = a; b <= n; ++b) { // a <= b, by uniknąć duplikatów for (int h = 1; h <= n; ++h) { int sum_of_squares = a * a + b * b + h * h; int d = sqrt(sum_of_squares); if (d * d == sum_of_squares && d <= n) { unique_aquariums.insert(make_tuple(a, b, h)); // poprawione wstawianie do zbioru } } } } cout << unique_aquariums.size() << endl; return 0; }
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 | #include <iostream> #include <cmath> #include <set> #include <tuple> using namespace std; int main() { int n; cin >> n; set<tuple<int, int, int>> unique_aquariums; for (int a = 1; a <= n; ++a) { for (int b = a; b <= n; ++b) { // a <= b, by uniknąć duplikatów for (int h = 1; h <= n; ++h) { int sum_of_squares = a * a + b * b + h * h; int d = sqrt(sum_of_squares); if (d * d == sum_of_squares && d <= n) { unique_aquariums.insert(make_tuple(a, b, h)); // poprawione wstawianie do zbioru } } } } cout << unique_aquariums.size() << endl; return 0; } |