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
44
45
46
47
48
49
50
#include <iostream>
#include <vector>

using namespace std;

#define REP(i,n,k) for (int i = k; i <= n; i++)
#define SIMPLEVEC vector<int>
#define LL long long

class Aquarium {
    int n{}, max{};
    SIMPLEVEC cnt;

public:
    void solve() {
        cin >> n;

        max = n * n;
        cnt.resize(max + 1, 0);

        REP(a, n, 1) {
            int a2 = a * a;
            REP(b, n, a) {
                int s = a2 + b * b;
                if (s > max) break;
                cnt[s]++;
            }
        }

        LL ans = 0;
        REP(d, n, 1) {
            int d2 = d * d;
            for (int h = 1; h < d; h++) {
                int s = d2 - h * h;
                if (s <= max) {
                    ans += cnt[s];
                }
            }
        }

        cout << ans << endl;
    }
};

int main() {
    Aquarium aquarium;
    aquarium.solve();

    return 0;
}