1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin>>n;
    int maxs=n*n-1;
    vector<int>licz(maxs);
    for(int a=1;a<n;a++){
        for(int b=a;;b++){
            if(a*a+b*b>maxs)break;
            licz[a*a+b*b]++;
        }
    }
    long long wyn=0;
    for(int d=1;d<=n;d++)
        for(int h=1;h<d;h++)
            if(d*d<=maxs+h*h)wyn+=licz[d*d-h*h];
    cout<<wyn;
    return 0;
}