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

constexpr int maxn = 5e3 + 7;
int n, a, b, res;
int pole[maxn][maxn];
int h[maxn * maxn];
int pref[maxn * maxn];


int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        h[i * i] = 1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            for(int k = 1; k <= n; k++){
                if(i * i + j * j + k * k <= n * n && h[i * i + j * j + k * k] == 1)
                    res++;
            }
        }
    }
    // for(int i = 1; i <= n; i++){
    //     for(int j = 1; j <= n; j++){
    //         pole[i][j] = n * n - i * i - j * j;
    //     }
    // }
    
    // for(int i = 1; i <= 5000 * 5000; i++){
    //     pref[i] = pref[i - 1] + h[i];
    // }
    // for(int i = 1; i <= n; i++){
    //     for(int j = 1; j <= n; j++){
    //         cout << pole[i][j] << " ";
    //         if(pole[i][j] > n * n) continue;
    //         res += pref[pole[i][j]];
    //     }
    //     cout << '\n';
    // }
    cout << res << '\n';
}