import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class Euler390 {
    static long seedFirstArea(long p) {
        return 8 * p * p * p + p;
    }

    static long maxSeed(long limit) {
        long lo = 0;
        long hi = 1;
        while (true) {
            if (hi > 2000000)
                break;
            if (seedFirstArea(hi) <= limit)
                hi *= 2;
            else
                break;
        }

        while (lo < hi) {
            long mid = lo + (hi - lo + 1) / 2;
            if (seedFirstArea(mid) <= limit) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        return lo;
    }

    static class State {
        long p;
        long q;
        long area;

        State(long p, long q, long area) {
            this.p = p;
            this.q = q;
            this.area = area;
        }
    }

    static long sumForSeed(long seed, long limit) {
        long total = 0;
        List<State> stack = new ArrayList<>();
        stack.add(new State(seed, 0, seed));

        BigInteger limitBi = BigInteger.valueOf(limit);

        while (!stack.isEmpty()) {
            State current = stack.remove(stack.size() - 1);
            BigInteger p = BigInteger.valueOf(current.p);
            BigInteger q = BigInteger.valueOf(current.q);
            BigInteger area = BigInteger.valueOf(current.area);

            BigInteger p2 = p.multiply(p);
            BigInteger a = BigInteger.valueOf(8).multiply(p2).add(BigInteger.ONE);
            BigInteger b = BigInteger.valueOf(4).multiply(p);
            BigInteger c = BigInteger.valueOf(4).multiply(p).multiply(
                    BigInteger.valueOf(4).multiply(p2).add(BigInteger.ONE));

            BigInteger q1 = a.multiply(q).add(b.multiply(area));
            BigInteger s1 = c.multiply(q).add(a.multiply(area));

            if (s1.compareTo(BigInteger.ZERO) > 0 && s1.compareTo(limitBi) <= 0) {
                long s1Long = s1.longValue();
                total += s1Long;

                long q1Long = q1.longValue();
                long pLong = current.p;

                stack.add(new State(pLong, q1Long, s1Long));
                stack.add(new State(q1Long, pLong, s1Long));
                stack.add(new State(q1Long, -pLong, s1Long));
            }
        }
        return total;
    }

    static String solve() {
        long limit = 10000000000L;
        long pmax = maxSeed(limit);
        if (pmax <= 0)
            return "0";

        long ans = 0;
        for (long seed = 1; seed <= pmax; seed++) {
            ans += sumForSeed(seed, limit);
        }
        return Long.toString(ans);
    }

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