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

public class Euler283 {
    static class Pair {
        int first, second;

        Pair(int f, int s) {
            first = f;
            second = s;
        }
    }

    static int[] buildSpf(int limit) {
        int[] spf = new int[limit + 1];
        if (limit >= 1)
            spf[1] = 1;
        for (int i = 2; i <= limit; ++i) {
            if (spf[i] != 0)
                continue;
            spf[i] = i;
            if ((long) i * i > limit)
                continue;
            for (int j = i * i; j <= limit; j += i) {
                if (spf[j] == 0)
                    spf[j] = i;
            }
        }
        return spf;
    }

    static void factorizeInt(int n, int[] spf, List<Pair> out) {
        out.clear();
        while (n > 1) {
            int p = spf[n];
            int cnt = 0;
            while (n % p == 0) {
                n /= p;
                ++cnt;
            }
            out.add(new Pair(p, cnt));
        }
    }

    static void mergeFactorizations(List<Pair> a, List<Pair> b, List<Pair> out) {
        out.clear();
        int i = 0, j = 0;
        while (i < a.size() || j < b.size()) {
            if (j == b.size() || (i < a.size() && a.get(i).first < b.get(j).first)) {
                out.add(a.get(i));
                ++i;
            } else if (i == a.size() || b.get(j).first < a.get(i).first) {
                out.add(b.get(j));
                ++j;
            } else {
                out.add(new Pair(a.get(i).first, a.get(i).second + b.get(j).second));
                ++i;
                ++j;
            }
        }
    }

    static void generateDivisors(List<Pair> factors, List<Long> divisors) {
        divisors.clear();
        divisors.add(1L);
        for (Pair p : factors) {
            int base = divisors.size();
            long mul = 1;
            for (int i = 1; i <= p.second; ++i) {
                mul *= p.first;
                for (int j = 0; j < base; ++j) {
                    divisors.add(divisors.get(j) * mul);
                }
            }
        }
    }

    static long solveRange(int kStart, int kEnd, int[] spf) {
        List<Pair> factorsN = new ArrayList<>();
        List<Pair> factorsM = new ArrayList<>();
        List<Pair> factorsAll = new ArrayList<>();
        List<Long> divisors = new ArrayList<>();

        long total = 0;

        for (int k = kStart; k <= kEnd; ++k) {
            long r = 2L * k;
            long n = r * r;
            factorizeInt((int) n, spf, factorsN);

            long xMax = (long) Math.sqrt(3L * n);
            for (long x = 1; x <= xMax; ++x) {
                long m = x * x + n;
                factorizeInt((int) m, spf, factorsM);
                mergeFactorizations(factorsN, factorsM, factorsAll);
                generateDivisors(factorsAll, divisors);

                long M = n * m;
                for (long u : divisors) {
                    if (u > M / u)
                        continue;
                    long v = M / u;
                    if ((u + n) % x != 0 || (v + n) % x != 0)
                        continue;

                    long y = (u + n) / x;
                    if (y < x)
                        continue;
                    long z = (v + n) / x;

                    total += 2L * (x + y + z);
                }
            }
        }
        return total;
    }

    public static String solve() {
        int kLimit = 1000;
        int threads = Math.max(1, Runtime.getRuntime().availableProcessors());

        int nMax = 4 * (2 * kLimit) * (2 * kLimit);
        int[] spf = buildSpf(nMax);

        if (threads <= 1 || kLimit < 100) {
            long ans = solveRange(1, kLimit, spf);
            return String.valueOf(ans);
        }

        int useThreads = Math.min(threads, kLimit);
        int chunk = (kLimit + useThreads - 1) / useThreads;

        ExecutorService executor = Executors.newFixedThreadPool(useThreads);
        List<Future<Long>> futures = new ArrayList<>();

        for (int t = 0; t < useThreads; ++t) {
            final int start = t * chunk + 1;
            final int end = Math.min(kLimit, start + chunk - 1);
            if (start > end)
                continue;

            futures.add(executor.submit(() -> solveRange(start, end, spf)));
        }

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

        return String.valueOf(total);
    }

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