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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
typedef pair <LL,LL> pll;
#define pb push_back
const int INF = 2147483647;
const int N = 25000005;

int i, a, b, c, a2, b2, c2, n, n2, res, tab[N];

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
n2 = n * n;
for (a=1;a<=n;a++) {
	a2 = a * a;
	for (b=1;b<=n;b++) {
		b2 = b * b;
		if (a2 + b2 > n2) break;
		tab[a2 + b2]++;
		if (a == b) tab[a2 + b2]++;
	}
}
for (a=1;a<=n;a++) for (b=a+1;b<=n;b++) res += tab[b * b - a * a];
cout << res / 2 << endl;
return 0;
}