// PA2025, @mjm, r3c-akw
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <functional>
using namespace std;
using lol = long long;
inline int nextInt() { int n; scanf("%d", &n); return n; }
inline lol myAbs(lol n) { return n >= 0 ? n : -n; }
const int N = 5000;
int hdCnt[N * N * 2 + 9];
int solve(int n) {
for (int d = 2; d <= n; ++d) {
int dd = d * d;
for (int h = 1; h < d; ++h) {
int hh = h * h;
++hdCnt[dd - hh];
}
}
int res = 0;
for (int a = 1; a < n; ++a) {
int aa = a * a;
for (int b = a; b < n; ++b) {
int bb = b * b;
res += hdCnt[aa + bb];
}
}
return res;
}
int main() {
int n = nextInt();
int res = solve(n);
printf("%d\n", res);
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 30 31 32 33 34 35 36 37 38 39 40 41 | // PA2025, @mjm, r3c-akw #include <cstdio> #include <vector> #include <set> #include <unordered_map> #include <algorithm> #include <functional> using namespace std; using lol = long long; inline int nextInt() { int n; scanf("%d", &n); return n; } inline lol myAbs(lol n) { return n >= 0 ? n : -n; } const int N = 5000; int hdCnt[N * N * 2 + 9]; int solve(int n) { for (int d = 2; d <= n; ++d) { int dd = d * d; for (int h = 1; h < d; ++h) { int hh = h * h; ++hdCnt[dd - hh]; } } int res = 0; for (int a = 1; a < n; ++a) { int aa = a * a; for (int b = a; b < n; ++b) { int bb = b * b; res += hdCnt[aa + bb]; } } return res; } int main() { int n = nextInt(); int res = solve(n); printf("%d\n", res); return 0; } |
English