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

public class Euler331 {

    static long isqrt(long n) {
        if (n < 0)
            return -1;
        if (n == 0)
            return 0;
        long x = (long) Math.sqrt((double) n);
        while ((x + 1) * (x + 1) <= n)
            x++;
        while (x * x > n)
            x--;
        return x;
    }

    static long isqrt_ceil(long n) {
        if (n <= 0)
            return 0;
        long r = isqrt(n);
        if (r * r == n)
            return r;
        return r + 1;
    }

    public static String solve() {
        long total_sum = 0;
        for (int i = 3; i <= 31; ++i) {
            long N = (1L << i) - i;
            total_sum += solveN(N);
        }
        return String.valueOf(total_sum);
    }

    static long solveN(long N) {
        if (N == 5)
            return 3;
        if (N % 2 != 0)
            return 0;

        byte[] rho = new byte[(int) N];
        long N_sq = N * N;
        long N_minus_1_sq = (N - 1) * (N - 1);

        int numThreads = Runtime.getRuntime().availableProcessors();
        if (numThreads <= 0)
            numThreads = 1;
        ExecutorService executor = Executors.newFixedThreadPool(numThreads);

        long chunk = N / numThreads;
        if (chunk == 0)
            chunk = N;

        AtomicLong n1 = new AtomicLong(0);

        CountDownLatch latch1 = new CountDownLatch(numThreads);
        for (int i = 0; i < numThreads; ++i) {
            final long start = i * chunk;
            final long end = (i == numThreads - 1) ? N : (i + 1) * chunk;
            if (start >= N) {
                latch1.countDown();
                continue;
            }

            executor.submit(() -> {
                long local_n1 = 0;
                for (long x = start; x < end; ++x) {
                    long x_sq = x * x;
                    long y_min_sq = (x_sq >= N_minus_1_sq) ? 0 : (N_minus_1_sq - x_sq);
                    long y_min = isqrt_ceil(y_min_sq);

                    long y_max_sq = N_sq - x_sq - 1;
                    if (y_max_sq < 0) {
                        rho[(int) x] = 0;
                        continue;
                    }
                    long y_max = isqrt(y_max_sq);

                    if (y_max >= y_min) {
                        long count = y_max - y_min + 1;
                        if (count % 2 != 0) {
                            rho[(int) x] = 1;
                            local_n1++;
                        } else {
                            rho[(int) x] = 0;
                        }
                    } else {
                        rho[(int) x] = 0;
                    }
                }
                n1.addAndGet(local_n1);
                latch1.countDown();
            });
        }

        try {
            latch1.await();
        } catch (Exception e) {
        }

        long N1 = n1.get();
        long N0 = N - N1;
        long ans = 2 * N0 * N1;

        AtomicLong totalAdj = new AtomicLong(0);
        CountDownLatch latch2 = new CountDownLatch(numThreads);

        for (int i = 0; i < numThreads; ++i) {
            final long start = i * chunk;
            final long end = (i == numThreads - 1) ? N : (i + 1) * chunk;
            if (start >= N) {
                latch2.countDown();
                continue;
            }
            executor.submit(() -> {
                long adj = 0;
                for (long x = start; x < end; ++x) {
                    long x_sq = x * x;
                    long y_min_sq = (x_sq >= N_minus_1_sq) ? 0 : (N_minus_1_sq - x_sq);
                    long y_min = isqrt_ceil(y_min_sq);

                    long y_max_sq = N_sq - x_sq - 1;
                    if (y_max_sq < 0)
                        continue;
                    long y_max = isqrt(y_max_sq);

                    if (y_max >= y_min) {
                        int rx = rho[(int) x];
                        for (long y = y_min; y <= y_max; ++y) {
                            int ry = rho[(int) y];
                            if (rx == ry)
                                adj += 1;
                            else
                                adj -= 1;
                        }
                    }
                }
                totalAdj.addAndGet(adj);
                latch2.countDown();
            });
        }

        try {
            latch2.await();
        } catch (Exception e) {
        }
        executor.shutdown();

        return ans + totalAdj.get();
    }

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