import java.util.*;
import java.util.concurrent.*;

public class Euler311 {
    static long isqrt(long n) {
        long r = (long) Math.sqrt(n);
        while ((r + 1) * (r + 1) <= n)
            r++;
        while (r * r > n)
            r--;
        return r;
    }

    static long isqrtCeil(long n) {
        long r = isqrt(n);
        return (r * r == n) ? r : r + 1;
    }

    static boolean isTwiceSquare(long n) {
        if ((n & 1) != 0)
            return false;
        long m = n >> 1;
        long r = isqrt(m);
        return r * r == m;
    }

    static long nChoose2(long n) {
        return (n < 2) ? 0 : (n * (n - 1)) / 2;
    }

    static long nChoose3(long n) {
        return (n < 3) ? 0 : (n * (n - 1) * (n - 2)) / 6;
    }

    static class BlockTask implements Callable<Long> {
        long low, high;

        BlockTask(long low, long high) {
            this.low = low;
            this.high = high;
        }

        @Override
        public Long call() {
            int len = (int) (high - low + 1);
            byte[] counts = new byte[len];

            for (long y = 1;; ++y) {
                long y2 = y * y;
                long min_n = y2 + (y + 1) * (y + 1);
                if (min_n > high)
                    break;

                long xMin = y + 1;
                long xMinN = y2 + xMin * xMin;
                if (xMinN < low) {
                    xMin = isqrtCeil(low - y2);
                    if (xMin <= y)
                        xMin = y + 1;
                }

                long xMax = isqrt(high - y2);
                if (xMax < xMin)
                    continue;

                long x2 = xMin * xMin;
                for (long x = xMin; x <= xMax; ++x) {
                    long n = y2 + x2;
                    int idx = (int) (n - low);
                    counts[idx]++;
                    x2 += 2 * x + 1;
                }
            }

            long blockSum = 0;
            for (int idx = 0; idx < len; ++idx) {
                int count = counts[idx];
                if (count >= 2) {
                    long n = low + idx;
                    blockSum += nChoose3(count);
                    if (isTwiceSquare(n)) {
                        blockSum += nChoose2(count);
                    }
                }
            }

            return blockSum;
        }
    }

    public static String solve() {
        long limit = 10000000000L;
        long maxT = limit / 4;
        long blockSpan = 4000000;

        int numThreads = Runtime.getRuntime().availableProcessors();
        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
        List<Future<Long>> futures = new ArrayList<>();

        long low = 1;
        while (low <= maxT) {
            long high = Math.min(maxT, low + blockSpan - 1);
            futures.add(executor.submit(new BlockTask(low, high)));
            low = high + 1;
        }

        long total = 0;
        try {
            for (Future<Long> f : futures) {
                total += f.get();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executor.shutdown();
        }

        return String.valueOf(total);
    }

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