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
#include <iostream>
#include <cmath> 
#include <chrono>

using namespace std;

int isSquare(int x) {
    int square = sqrt(x);
    if (x == square * square) return square;
    return 0;
}

int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    int n;
    cin >> n;

    auto start = chrono::steady_clock::now();

    auto n2 = n * n;
    int wynik = 0;
    for (int a = 1; a < n; a++) {
        auto a2 = a * a;
        for (int b = a; b < n; b++) {
            auto b2 = b * b;
            if (a2 + b2 >= n2) break;
            for (int h = 1; h < n; h++) {
                auto p = a2 + b2 + h * h;
                if (p > n2) break;
                int diag = isSquare(p);
                if (diag > 0)
                {
                    wynik++;
                    //cout << wynik << ". (" << a << "," << b << ") " << h << " - " << diag << endl;
                }
            }
        }
    }
    cout << wynik << endl;

    //auto end = chrono::steady_clock::now();
    //chrono::duration<double> elapsed_seconds = end - start;
    //cout << "Czas: " << elapsed_seconds.count() << " sekund" << endl;

}