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

using ll = int64_t;

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N;
	cin >> N;
	vector<ll> c1(N*N+1, 0);
	vector<ll> c2(N*N+1, 0);
	for(int a = 1; a <= N; a++){
		for(int b = a; b*b + a*a <= N*N; b++){
			int val = a*a+b*b;
			c1[val] += 1;
		}
	}
	for(int d = 1; d <= N; d++){
		for(int h = 1; h < d; h++){
			c2[d*d-h*h]+=1;
		}
	}
	ll ans = 0;
	for(int x = 0; x <= N*N; x++){
		ans += c1[x] * c2[x];
	}
	cout << ans << '\n';
}