import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.Callable;

public class Euler730 {
    static class Triple {
        long p, q, r;

        Triple(long p, long q, long r) {
            this.p = p;
            this.q = q;
            this.r = r;
        }
    }

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

    static boolean isSquare(long v, long[] root) {
        if (v < 0)
            return false;
        long r = isqrt(v);
        if (r * r == v) {
            root[0] = r;
            return true;
        }
        return false;
    }

    static boolean hasParent(Triple t) {
        long p = t.p, q = t.q, r = t.r;
        long x3 = -2 * p - 2 * q + 3 * r;
        if (x3 <= 0)
            return false;

        long x1 = p + 2 * q - 2 * r;
        long x2 = -2 * p - q + 2 * r;
        if (x1 > 0 && x2 > 0)
            return true;

        x2 = 2 * p + q - 2 * r;
        if (x1 > 0 && x2 > 0)
            return true;

        x1 = -p - 2 * q + 2 * r;
        if (x1 > 0 && x2 > 0)
            return true;

        return false;
    }

    static long gcd(long a, long b) {
        while (b != 0) {
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    static List<List<Triple>> buildRoots(int m) {
        int limit = Math.max(4 * m, 10);
        List<List<Triple>> roots = new ArrayList<>(m + 1);
        for (int k = 0; k <= m; ++k) {
            roots.add(new ArrayList<>());
        }
        long[] root = new long[1];
        for (int k = 0; k <= m; ++k) {
            for (long p = 1; p <= limit; ++p) {
                for (long q = p; q <= limit; ++q) {
                    long v = p * p + q * q + k;
                    if (!isSquare(v, root))
                        continue;
                    long r = root[0];
                    if (gcd(p, gcd(q, r)) != 1)
                        continue;
                    Triple t = new Triple(p, q, r);
                    if (!hasParent(t)) {
                        roots.get(k).add(t);
                    }
                }
            }
        }
        return roots;
    }

    static class CountPair {
        long total, diag;

        CountPair(long total, long diag) {
            this.total = total;
            this.diag = diag;
        }
    }

    static CountPair countFromRoot(Triple root, long n) {
        List<Triple> stack = new ArrayList<>();
        stack.add(root);
        long count = 0;
        long diag = 0;

        while (!stack.isEmpty()) {
            Triple cur = stack.remove(stack.size() - 1);
            long per = cur.p + cur.q + cur.r;
            if (per > n)
                continue;
            count++;
            if (cur.p == cur.q)
                diag++;

            Triple a = new Triple(cur.p - 2 * cur.q + 2 * cur.r,
                    2 * cur.p - cur.q + 2 * cur.r,
                    2 * cur.p - 2 * cur.q + 3 * cur.r);
            if (a.p + a.q + a.r <= n)
                stack.add(a);

            Triple b = new Triple(cur.p + 2 * cur.q + 2 * cur.r,
                    2 * cur.p + cur.q + 2 * cur.r,
                    2 * cur.p + 2 * cur.q + 3 * cur.r);
            if (b.p + b.q + b.r <= n)
                stack.add(b);

            Triple c = new Triple(-cur.p + 2 * cur.q + 2 * cur.r,
                    -2 * cur.p + cur.q + 2 * cur.r,
                    -2 * cur.p + 2 * cur.q + 3 * cur.r);
            if (c.p + c.q + c.r <= n)
                stack.add(c);
        }
        return new CountPair(count, diag);
    }

    static class Task {
        int k;
        Triple root;

        Task(int k, Triple root) {
            this.k = k;
            this.root = root;
        }
    }

    public static String solve() {
        int m = 100;
        long n = 100000000L;

        List<List<Triple>> roots = buildRoots(m);
        List<Task> tasks = new ArrayList<>();
        for (int k = 0; k <= m; ++k) {
            for (Triple r : roots.get(k)) {
                tasks.add(new Task(k, r));
            }
        }

        if (tasks.isEmpty())
            return "0";

        int threads = Math.min(16, Math.max(1, Runtime.getRuntime().availableProcessors()));
        threads = Math.min(threads, tasks.size());

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Future<long[]>> futures = new ArrayList<>();

        int chunkSize = Math.max(1, tasks.size() / threads);

        for (int i = 0; i < tasks.size(); i += chunkSize) {
            final List<Task> chunk = tasks.subList(i, Math.min(i + chunkSize, tasks.size()));
            futures.add(executor.submit(() -> {
                long[] localCounts = new long[m + 1];
                for (Task task : chunk) {
                    long per = task.root.p + task.root.q + task.root.r;
                    if (per > n)
                        continue;
                    CountPair cnt = countFromRoot(task.root, n);
                    if (cnt.diag > 0) {
                        localCounts[task.k] += (cnt.total + cnt.diag) / 2;
                    } else {
                        localCounts[task.k] += cnt.total;
                    }
                }
                return localCounts;
            }));
        }

        long total = 0;
        try {
            for (Future<long[]> f : futures) {
                long[] res = f.get();
                for (int k = 0; k <= m; ++k) {
                    total += res[k];
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        executor.shutdown();

        return Long.toString(total);
    }

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