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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long double ld;
typedef unordered_map<int, int> umii;
typedef vector<pair<ll,ll>> vpll;
typedef tuple<int,int,int> tp;
const ll MOD = 1e9+696969;

void solve()
{
   int n;
   cin >> n;

   ll m=n*n;

   vll count(m+1,0);

   for(int i=1; i<=n; i++)
   {
        ll i2=i*i;
        int bmax=(int)floor(sqrt((double)m-i2));
        for(int j=i; j<=bmax; ++j)
        {
            int s=i2+j*j;
            if(s<=m)
            count[s]++;
        }
   }

   ll ans=0;
   for(int i=1; i<=n; ++i)
   {
        ll i2=i*i;

        for(int j=1; j<i; ++j)
        {
            int s=i2 -j*j;
            if(s<=m and s>=0)
            ans+=count[s];
        }

   }

   cout << ans;
}

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

    solve();
    return 0;
}