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
#include <bits/stdc++.h>
using namespace std;

typedef int64_t ll;
typedef uint64_t ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
constexpr ll LINF = 1e18;
constexpr int INF = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> bases(2 * n * n);
    for (int a = 1; a < n; ++a) {
        for (int b = a; b < n; ++b) {
            bases[a * a + b * b] += 1;
        }
    }

    ll cnt = 0;
    for (int sum = 2; sum <= n; ++sum) {
        for (int h = 1; h < sum; ++h) {
            cnt += bases[sum * sum - h * h];
        }
    }
    cout << cnt << endl;

    return 0;
}