#include <iostream> #include <cstdint> namespace { using uint_t = uint_fast32_t; using std::cin, std::cout; constexpr uint_t START = 3; } int main() { uint_t n; uint_t wynik = 0; cin >> n; if (n < START) { cout << wynik << '\n'; return 0; } uint_t a, b, r2, odl; for (uint_t h = 1; h < n; ++h) for (uint_t k = START >= h + 1 ? START : h + 1; k <= n; ++k) { a = k; b = 1; r2 = k * k - h * h; while (a >= b) { odl = a * a + b * b; if (odl > r2) { --a; } else if (odl < r2) { ++b; } else { ++wynik; --a; } } } cout << wynik << '\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 33 34 35 36 37 38 39 40 41 | #include <iostream> #include <cstdint> namespace { using uint_t = uint_fast32_t; using std::cin, std::cout; constexpr uint_t START = 3; } int main() { uint_t n; uint_t wynik = 0; cin >> n; if (n < START) { cout << wynik << '\n'; return 0; } uint_t a, b, r2, odl; for (uint_t h = 1; h < n; ++h) for (uint_t k = START >= h + 1 ? START : h + 1; k <= n; ++k) { a = k; b = 1; r2 = k * k - h * h; while (a >= b) { odl = a * a + b * b; if (odl > r2) { --a; } else if (odl < r2) { ++b; } else { ++wynik; --a; } } } cout << wynik << '\n'; } |