#include <iostream> #include <map> #include <set> template <uint64_t N> struct squares_t { constexpr squares_t() : arr() { for (auto i = 0; i <= N; ++i) { arr[i] = i*i; } } uint64_t arr[N+1]; }; void prog_main(std::istream& in, std::ostream& out) { uint32_t n; in >> n; constexpr auto sq = squares_t<5000>(); std::set<uint64_t> s(sq.arr, sq.arr + 5001); const uint64_t max = sq.arr[n]; uint32_t total = 0; for (uint32_t i = 1; i <= n; ++i) { for (uint32_t j = i; j <= n; ++j) { uint64_t base = sq.arr[i] + sq.arr[j]; if ( base > max ) { break; } for (uint32_t k = 1; k <= n; k++) { uint64_t temp = base + sq.arr[k]; if ((temp <= max)) { if (s.find(temp) != s.end()) { ++ total; } } else { break; } } } } out << total << std::endl; } #ifndef TEST int main(int argc, char* argv[]) { prog_main(std::cin, std::cout); return 0; } #endif
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 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <map> #include <set> template <uint64_t N> struct squares_t { constexpr squares_t() : arr() { for (auto i = 0; i <= N; ++i) { arr[i] = i*i; } } uint64_t arr[N+1]; }; void prog_main(std::istream& in, std::ostream& out) { uint32_t n; in >> n; constexpr auto sq = squares_t<5000>(); std::set<uint64_t> s(sq.arr, sq.arr + 5001); const uint64_t max = sq.arr[n]; uint32_t total = 0; for (uint32_t i = 1; i <= n; ++i) { for (uint32_t j = i; j <= n; ++j) { uint64_t base = sq.arr[i] + sq.arr[j]; if ( base > max ) { break; } for (uint32_t k = 1; k <= n; k++) { uint64_t temp = base + sq.arr[k]; if ((temp <= max)) { if (s.find(temp) != s.end()) { ++ total; } } else { break; } } } } out << total << std::endl; } #ifndef TEST int main(int argc, char* argv[]) { prog_main(std::cin, std::cout); return 0; } #endif |