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
#include <iostream>
#include <map>
using namespace std;
struct SquareSumAB : map< int, int > {
  SquareSumAB(int n) {
    int a, aa, b, nn = n * n, v;
    for (a = 1; a <= n; ++a)
      for (aa = a * a, b = a; (v = (aa + b * b)) <= nn; ++b)
        (*this)[v]++;
  }
};
int solve(int n) {
  int result = 0;
  SquareSumAB ab(n);
  int i, ii, h;
  for (i = 1; i <= n; ++i)
    for (ii = i * i, h = 1; h <= i; ++h) {
      map< int, int >::iterator it = ab.find(ii - h * h);
      if (it != ab.end())
        result += it->second;
    }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  cout << solve(n) << '\n';
}