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
52
53
// Akw.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <cmath>

static int isSquare(int n)
{
    int m = sqrt(n);
    return m * m == n ? m : 0;
}

static int findQuadraples(int range)
{
    int total = 0;

    for (int a = 1; a <= range; a++)
    {
        for (int b = a; b <= range; b++)
        {
            for (int c = 1; c <= range; c++)
            {
                int sum = a * a + b * b + c * c;
                int d = isSquare(sum);

                if (d != 0)
                {
                    if (d <= range)
                    {
                        total++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    return total;
}

int main()
{
    int n;

    std::cin >> n;

    std::cout << findQuadraples(n);

    return 0;
}