import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.math.BigInteger;

public class Euler972 {

    static class Point {
        long x, y, z;

        Point(long x, long y, long z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    static class Key implements Comparable<Key> {
        long u, v;

        Key(long u, long v) {
            this.u = u;
            this.v = v;
        }

        @Override
        public int compareTo(Key o) {
            if (this.u != o.u)
                return Long.compare(this.u, o.u);
            return Long.compare(this.v, o.v);
        }
    }

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

    static long lcm(long a, long b) {
        if (a == 0 && b == 0)
            return 0;
        return Math.abs(a * b) / gcd(a, b);
    }

    static long computeT(int n) {
        long L = 1;
        for (int d = 1; d <= n; ++d) {
            L = lcm(L, d);
        }

        List<Long> coordsList = new ArrayList<>();
        for (int d = 1; d <= n; ++d) {
            long q = L / d;
            for (int num = -d + 1; num <= d - 1; ++num) {
                coordsList.add((long) num * q);
            }
        }

        List<Long> coords = coordsList.stream().distinct().sorted().collect(Collectors.toList());

        long L2 = L * L;
        List<Point> pts = new ArrayList<>();

        for (long x : coords) {
            long x2 = x * x;
            for (long y : coords) {
                long y2 = y * y;
                if (x2 + y2 >= L2)
                    continue;
                pts.add(new Point(x * L, y * L, x2 + y2 + L2));
            }
        }

        long count = 0;
        List<Key> keys = new ArrayList<>(pts.size());

        for (int i = 0; i < pts.size() - 2; ++i) {
            Point p = pts.get(i);
            keys.clear();

            for (int j = i + 1; j < pts.size(); ++j) {
                Point q = pts.get(j);
                BigInteger u, v;

                if (p.x == 0) {
                    u = BigInteger.valueOf(q.x);
                    v = BigInteger.valueOf(p.z).multiply(BigInteger.valueOf(q.y))
                            .subtract(BigInteger.valueOf(p.y).multiply(BigInteger.valueOf(q.z)));
                } else {
                    u = BigInteger.valueOf(p.y).multiply(BigInteger.valueOf(q.x))
                            .subtract(BigInteger.valueOf(p.x).multiply(BigInteger.valueOf(q.y)));
                    v = BigInteger.valueOf(p.z).multiply(BigInteger.valueOf(q.x))
                            .subtract(BigInteger.valueOf(p.x).multiply(BigInteger.valueOf(q.z)));
                }

                long uu = u.longValue();
                long vv = v.longValue();
                long g = gcd(uu, vv);
                if (g == 0)
                    g = 1;

                uu /= g;
                vv /= g;

                if (uu < 0 || (uu == 0 && vv < 0)) {
                    uu = -uu;
                    vv = -vv;
                }

                keys.add(new Key(uu, vv));
            }

            Collections.sort(keys);
            for (int s = 0; s < keys.size();) {
                int t = s + 1;
                while (t < keys.size() && keys.get(t).u == keys.get(s).u && keys.get(t).v == keys.get(s).v) {
                    t++;
                }
                long cnt = t - s;
                count += cnt * (cnt - 1) / 2;
                s = t;
            }
        }

        return 6 * count;
    }

    public static String solve() {
        return Long.toString(computeT(12));
    }

    public static void main(String[] args) {
        int n = 12;
        boolean runCheckpoints = true;

        for (String arg : args) {
            if (arg.equals("--skip-checkpoints")) {
                runCheckpoints = false;
            } else if (arg.startsWith("--n=")) {
                n = Integer.parseInt(arg.substring(4));
            }
        }

        if (runCheckpoints) {
            if (computeT(2) != 24) {
                System.out.println("Validation failed");
                return;
            }
            if (computeT(3) != 1296) {
                System.out.println("Validation failed");
                return;
            }
            if (computeT(4) != 5052) {
                System.out.println("Validation failed");
                return;
            }
        }

        System.out.println(computeT(n));
    }
}
