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

public class Euler572 {
    static int gcd3(int a, int b, int c) {
        a = Math.abs(a);
        b = Math.abs(b);
        c = Math.abs(c);
        long g = a;
        long h = b;
        while (h != 0) {
            long t = g % h;
            g = h;
            h = t;
        }
        long r = c;
        while (r != 0) {
            long t = g % r;
            g = r;
            r = t;
        }
        return (int) g;
    }

    static boolean canonicalU(int a, int b, int c) {
        if (a != 0)
            return a > 0;
        if (b != 0)
            return b > 0;
        return c > 0;
    }

    static long floorDiv(long a, long b) {
        long q = a / b;
        long r = a % b;
        if (r != 0 && ((r > 0) != (b > 0)))
            q--;
        return q;
    }

    static long ceilDiv(long a, long b) {
        return -floorDiv(-a, b);
    }

    static long countSolutionsSymmetric(int a, int b, int c, int V) {
        if (V < 0)
            return 0;
        int len = 2 * V + 1;

        boolean za = (a == 0), zb = (b == 0), zc = (c == 0);
        int zcnt = (za ? 1 : 0) + (zb ? 1 : 0) + (zc ? 1 : 0);

        if (zcnt == 2) {
            int coef = !za ? a : (!zb ? b : c);
            if (coef == 0)
                return 0;
            if (1 % coef != 0)
                return 0;
            int x = 1 / coef;
            if (Math.abs(x) > V)
                return 0;
            return (long) len * len;
        }

        if (zcnt == 1) {
            if (c == 0) {
                long cnt = 0;
                for (int x = -V; x <= V; x++) {
                    int rem = 1 - a * x;
                    if (rem % b != 0)
                        continue;
                    int y = rem / b;
                    if (Math.abs(y) <= V)
                        cnt += len;
                }
                return cnt;
            }
            if (b == 0) {
                long cnt = 0;
                for (int x = -V; x <= V; x++) {
                    int rem = 1 - a * x;
                    if (rem % c != 0)
                        continue;
                    int z = rem / c;
                    if (Math.abs(z) <= V)
                        cnt += len;
                }
                return cnt;
            }
            long cnt = 0;
            for (int y = -V; y <= V; y++) {
                int rem = 1 - b * y;
                if (rem % c != 0)
                    continue;
                int z = rem / c;
                if (Math.abs(z) <= V)
                    cnt += len;
            }
            return cnt;
        }

        int[] coef = { a, b, c };
        int pivot = 0;
        for (int k = 0; k < 3; k++) {
            if (Math.abs(coef[k]) == 1) {
                pivot = k;
                break;
            }
            if (Math.abs(coef[k]) > Math.abs(coef[pivot]))
                pivot = k;
        }
        int i = (pivot + 1) % 3;
        int j = (pivot + 2) % 3;

        long cnt = 0;
        for (int xi = -V; xi <= V; xi++) {
            for (int xj = -V; xj <= V; xj++) {
                int rem = 1 - coef[i] * xi - coef[j] * xj;
                int den = coef[pivot];
                if (rem % den != 0)
                    continue;
                int xp = rem / den;
                if (Math.abs(xp) <= V)
                    cnt++;
            }
        }
        return cnt;
    }

    static class Range {
        int lo, hi;

        Range(int lo, int hi) {
            this.lo = lo;
            this.hi = hi;
        }

        int len() {
            return hi >= lo ? (hi - lo + 1) : 0;
        }
    }

    static Range intersect(Range a, Range b) {
        return new Range(Math.max(a.lo, b.lo), Math.min(a.hi, b.hi));
    }

    static long countSolutionsBox(int a, int b, int c, Range r0, Range r1, Range r2) {
        if (r0.len() == 0 || r1.len() == 0 || r2.len() == 0)
            return 0;

        int[] coef = { a, b, c };
        Range[] rr = { r0, r1, r2 };

        boolean za = (a == 0), zb = (b == 0), zc = (c == 0);
        int zcnt = (za ? 1 : 0) + (zb ? 1 : 0) + (zc ? 1 : 0);
        if (zcnt == 3)
            return 0;

        if (zcnt == 2) {
            int k = !za ? 0 : (!zb ? 1 : 2);
            int den = coef[k];
            if (1 % den != 0)
                return 0;
            int x = 1 / den;
            return (x < rr[k].lo || x > rr[k].hi) ? 0 : (long) rr[(k + 1) % 3].len() * rr[(k + 2) % 3].len();
        }

        if (zcnt == 1) {
            int freeK = za ? 0 : (zb ? 1 : 2);
            int i = (freeK + 1) % 3;
            int j = (freeK + 2) % 3;
            long cnt2 = 0;
            for (int xi = rr[i].lo; xi <= rr[i].hi; xi++) {
                int rem = 1 - coef[i] * xi;
                int den = coef[j];
                if (rem % den != 0)
                    continue;
                int xj = rem / den;
                if (xj >= rr[j].lo && xj <= rr[j].hi)
                    cnt2++;
            }
            return cnt2 * rr[freeK].len();
        }

        int bestPivot = -1;
        long bestCost = Long.MAX_VALUE;
        for (int k = 0; k < 3; k++) {
            if (coef[k] == 0)
                continue;
            int i = (k + 1) % 3;
            int j = (k + 2) % 3;
            long cost = (long) rr[i].len() * rr[j].len();
            if (cost < bestCost || (cost == bestCost && Math.abs(coef[k]) == 1)) {
                bestCost = cost;
                bestPivot = k;
            }
        }

        int k = bestPivot;
        int i = (k + 1) % 3;
        int j = (k + 2) % 3;

        long cnt = 0;
        for (int xi = rr[i].lo; xi <= rr[i].hi; xi++) {
            for (int xj = rr[j].lo; xj <= rr[j].hi; xj++) {
                int rem = 1 - coef[i] * xi - coef[j] * xj;
                int den = coef[k];
                if (rem % den != 0)
                    continue;
                int xk = rem / den;
                if (xk >= rr[k].lo && xk <= rr[k].hi)
                    cnt++;
            }
        }
        return cnt;
    }

    static long computeC(int n) {
        long base = 1 + (n >= 1 ? 1 : 0);

        int threads = Runtime.getRuntime().availableProcessors();
        if (threads <= 0)
            threads = 1;
        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Callable<long[]>> tasks = new ArrayList<>();

        int aMin = -n;
        int aMax = n;
        int totalA = aMax - aMin + 1;
        int block = (totalA + threads - 1) / threads;

        for (int t = 0; t < threads; t++) {
            final int alo = aMin + t * block;
            final int ahi = Math.min(aMax, alo + block - 1);
            if (alo > ahi)
                continue;
            tasks.add(() -> {
                long r1 = 0, r2 = 0;
                for (int a = alo; a <= ahi; a++) {
                    for (int b = -n; b <= n; b++) {
                        for (int c = -n; c <= n; c++) {
                            if (a == 0 && b == 0 && c == 0)
                                continue;
                            if (!canonicalU(a, b, c))
                                continue;
                            if (gcd3(a, b, c) != 1)
                                continue;

                            int Umax = Math.max(Math.abs(a), Math.max(Math.abs(b), Math.abs(c)));
                            int V = n / Umax;
                            if (V > 0) {
                                r1 += countSolutionsSymmetric(a, b, c, V);
                            }

                            Range[] rv = {
                                    new Range(-n - 1, n + 1),
                                    new Range(-n - 1, n + 1),
                                    new Range(-n - 1, n + 1)
                            };

                            int[] u = { a, b, c };
                            for (int j = 0; j < 3; j++) {
                                int maxOther = 0;
                                for (int i = 0; i < 3; i++) {
                                    if (i == j)
                                        continue;
                                    maxOther = Math.max(maxOther, Math.abs(u[i]));
                                }
                                if (maxOther > 0) {
                                    int off = n / maxOther;
                                    rv[j] = intersect(rv[j], new Range(-off, off));
                                }
                                if (u[j] != 0) {
                                    long lo, hi;
                                    if (u[j] > 0) {
                                        lo = ceilDiv(1L - n, u[j]);
                                        hi = floorDiv(1L + n, u[j]);
                                    } else {
                                        lo = ceilDiv(1L + n, u[j]);
                                        hi = floorDiv(1L - n, u[j]);
                                    }
                                    rv[j] = intersect(rv[j], new Range((int) lo, (int) hi));
                                }
                            }
                            r2 += countSolutionsBox(a, b, c, rv[0], rv[1], rv[2]);
                        }
                    }
                }
                return new long[] { r1, r2 };
            });
        }

        long rank1 = 0;
        long rank2 = 0;
        try {
            for (Future<long[]> res : executor.invokeAll(tasks)) {
                long[] part = res.get();
                rank1 += part[0];
                rank2 += part[1];
            }
        } catch (Exception e) {
        }
        executor.shutdown();

        return base + rank1 + rank2;
    }

    public static String solve() {
        return String.valueOf(computeC(200));
    }

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