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
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main(){
    int n, k, c;
    vector<int> squares;
    set<int> square_set;
    cin >> n;
    k = 0;
    
    for(int i = 0; i <= n; i++){
        squares.push_back(i*i);
        square_set.insert(i*i);
        //cout << "ii " << i*i << "\n";
    }

    for(int i = 1; i < n; i++){
        for(int j = i; j < n; j++){
            for(int h = j; h < n; h++){
                c = squares[i]+squares[j]+squares[h];
                if(square_set.find(c) != square_set.end()){
                    if(i == j && i == h){
                        k += 1;
                        //cout << c << " 1t" << "\n";
                    }
                    else if(i == j || i == h || j == h){
                        k += 2;
                        //cout << c << " 2t" << "\n";
                    }
                    else if (i != j && i != h && j != h){
                        k += 3;
                        //cout << c << " 3t " << i << j << h << "\n";
                    }
                    //cout << c << "\n";
                }
            }
        }
    }
    cout << k;

}