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
66
67
68
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn = 5000*5000 + 10;

vector<LL> sito(maxn);

LL sum_of_squares(LL N)
{
	bool is_square = 1;
	LL res = 1;
	LL n = N;
	while (n > 1)
	{
		LL d = sito[n];
		LL cnt = 0;
		while (n%d == 0)
		{
			n /= d;
			cnt++;
		}
		if (cnt%2 == 1)
			is_square = 0;
		if (d%4 == 3 && cnt%2 == 1)
			return 0;
		if (d%4 == 1)
			res *= (cnt+1);
	}
	res -= is_square;
	LL k = sqrt(N/2);
	bool same = (N%2 == 0 && k*k == N/2);
	return (res + same) / 2;
}

LL solve(LL n)
{
	LL ans = 0;
	for (LL k = 1; k <= n; k++)
	{
		for (LL c = 1; c < k; c++)
		{
			LL x = k*k - c*c;
			ans += sum_of_squares(x);
		}
	}
	return ans;
}

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

	for (LL i = 2; i < maxn; i++)
	{
		if (sito[i] == 0)
		{
			for (LL j = i; j < maxn; j += i)
			{
				if (sito[j] == 0)
					sito[j] = i;
			}
		}
	}

	LL n;
	cin >> n;
	cout << solve(n) << "\n";
}