public class Euler919 {

    static class Pair {
        long k, l;

        Pair(long k, long l) {
            this.k = k;
            this.l = l;
        }
    }

    static long isqrt(long x) {
        long r = (long) Math.sqrt((double) x);
        while ((r + 1) * (r + 1) <= x) {
            ++r;
        }
        while (r * r > x) {
            --r;
        }
        return r;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static long fortunateSumFast(long perimeterLimit) {
        Pair[] coeffs = {
                new Pair(1, 15), new Pair(3, 5), new Pair(5, 3), new Pair(15, 1),
                new Pair(2, 30), new Pair(6, 10), new Pair(10, 6), new Pair(30, 2)
        };

        long ans = 0;

        for (Pair pPair : coeffs) {
            long k = pPair.k;
            long l = pPair.l;
            for (long r = 1;; ++r) {
                long sm = k * r * r;
                if (sm > 4L * perimeterLimit)
                    break;

                for (long s = 1;; ++s) {
                    long df = l * s * s;
                    if (df >= sm)
                        break;

                    if (gcd(r, s) != 1)
                        continue;
                    if (((sm + df) & 1L) != 0)
                        continue;

                    long x = (sm + df) / 2;
                    long y = (sm - df) / 2;
                    long z2 = (x * x - y * y) / 15;

                    long z = isqrt(z2);
                    if (z * z != z2)
                        continue;
                    if (gcd(x, gcd(y, z)) != 1)
                        continue;

                    long a = x;
                    long b = y + z;
                    long c = z;
                    while ((a & 3L) != 0 || (b & 3L) != 0) {
                        a <<= 1;
                        b <<= 1;
                        c <<= 1;
                    }
                    a >>= 2;
                    b >>= 2;
                    if (gcd(a, gcd(b, c)) <= 1) {
                        if (a + b + c > 2L * Math.max(a, Math.max(b, c)) && b >= c) {
                            long p = a + b + c;
                            long ct = perimeterLimit / p;
                            ans += p * ct * (ct + 1) / 2;
                        }
                    }

                    if (z >= y)
                        continue;

                    a = x;
                    b = y - z;
                    c = z;
                    while ((a & 3L) != 0 || (b & 3L) != 0) {
                        a <<= 1;
                        b <<= 1;
                        c <<= 1;
                    }
                    a >>= 2;
                    b >>= 2;
                    if (gcd(a, gcd(b, c)) <= 1) {
                        if (a + b + c > 2L * Math.max(a, Math.max(b, c)) && b >= c) {
                            long p = a + b + c;
                            long ct = perimeterLimit / p;
                            ans += p * ct * (ct + 1) / 2;
                        }
                    }
                }
            }
        }

        return ans;
    }

    public static String solve() {
        return Long.toString(fortunateSumFast(10000000L));
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
