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
#include <iostream>
#include <algorithm>

const int MAX = 5000+2;

int SC[MAX*MAX*2];

void init(int n) {
    for (int i=1;i<=n;++i) {
        for (int j=i;j<=n;++j) {
            SC[i*i+j*j]++;
        }
    }
}

int main() {
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    init(n);

    int64_t c = 0;
    for (int i=1;i<=n;++i) {
        int sc = i*i;
        for (int h=1;h<i;++h) {
            c += SC[sc-h*h];
        }
    }
    std::cout << c << std::endl;

    return 0;
}