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
#include<cstdio>
#include<cmath>

using namespace std;

int main() {
    int limit;
    scanf("%d\n", &limit);

    long long res = 0;
    for (int a = 1; a <= limit; a++) {
        for (int b = a; b <= (int) sqrt((double) limit * limit - 2 * a * a); b++) {
            for (int c = b; c <= (int) sqrt((double) (limit * limit - a * a - b * b)); c++) {
                int p = a*a + b*b + c*c;
                int d = ((int) sqrt((double) p));
                if (d * d == p && d <= limit) {
                    if (a == b && b == c) {
                        res++;
                    } else if (a == b || a == c || b == c) {
                        res += 2;
                    } else {
                        res += 3;
                    }
                }
            }
        }
    }

    printf("%lld\n", res);

    return 0;
}