#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
using ll = long long;
using namespace std;
const int N = 5000;
const int M = N * N + 5;
int cnt_ab[M], cnt_dh[M];
int main() {
int n;
scanf("%d", &n);
for (int a = 1; a <= n; a++) {
int max_b = sqrt(n * n - a * a) + 1;
for (int b = a; b <= max_b; b++) {
cnt_ab[a * a + b * b]++;
}
}
for (int d = 1; d <= n; d++) {
for (int h = 1; h < d; h++) {
cnt_dh[d * d - h * h]++;
}
}
int nn = n * n;
int res = 0;
for (int i = 1; i < nn; i++) {
res += cnt_ab[i] * cnt_dh[i];
}
printf("%d\n", res);
}
// g++ -std=c++17 -Wall -Wextra -Wshadow C.cpp -o C
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 | #include <cstdio> #include <vector> #include <utility> #include <cmath> #include <algorithm> using ll = long long; using namespace std; const int N = 5000; const int M = N * N + 5; int cnt_ab[M], cnt_dh[M]; int main() { int n; scanf("%d", &n); for (int a = 1; a <= n; a++) { int max_b = sqrt(n * n - a * a) + 1; for (int b = a; b <= max_b; b++) { cnt_ab[a * a + b * b]++; } } for (int d = 1; d <= n; d++) { for (int h = 1; h < d; h++) { cnt_dh[d * d - h * h]++; } } int nn = n * n; int res = 0; for (int i = 1; i < nn; i++) { res += cnt_ab[i] * cnt_dh[i]; } printf("%d\n", res); } // g++ -std=c++17 -Wall -Wextra -Wshadow C.cpp -o C |
English