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

using std::cin, std::cout;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
const char endl = '\n';

const int MAX_N = 5005;
bool is_square[MAX_N];
int heights[MAX_N*MAX_N];
int n;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            heights[i*i - j*j]++;
        }
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            cnt += heights[i*i + j*j];
        }
    }

    cout << cnt;

    cout << endl;
    return 0;
}