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

int n;

int c1[5007*5007]; //ile jest par ze a^2 + b^2 = i
int dp[5007*5007]; //ile jest trojek ze a^2 + b^2 + c^2 = i  

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n;
	
	for(int i=1; i<=5000; i++){
		for(int j=1; j<=5000; j++){
			if(i*i + j*j > 5000*5000) break;
			c1[i*i + j*j]++;
		}
	}
	
	for(int i=1; i<=5000*5000; i++) c1[i] = (c1[i]+1)/2;	
	
	for(int i=3; i<=5000; i++){
		for(int h=1; h<=5000; h++){
			if(h*h <= i*i) dp[i] += c1[i*i -h*h];
		}
	}
	
	int ans = 0;
	for(int i=1; i<=n; i++) ans += dp[i];
	
	cout << ans << '\n';
	
	return 0;
}