import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Euler299 {
    static int gcd(int a, int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    static long countXEqYWorker(int lo, int hi, long limit, long numerator) {
        long local = 0;
        for (int m = lo; m < hi; ++m) {
            long m2 = (long) m * m;

            if ((m & 1) != 0) {
                for (int n = 1;; ++n) {
                    long s = m2 + 4L * m * n + 2L * n * n;
                    if (s >= limit)
                        break;
                    if (gcd(m, n) == 1) {
                        local += numerator / s;
                    }
                }
            }

            for (int n = 1;; ++n) {
                long s = 2L * m2 + 4L * m * n + (long) n * n;
                if (s >= limit)
                    break;
                if ((n & 1) != 0 && gcd(m, n) == 1) {
                    local += numerator / s;
                }
            }
        }
        return local;
    }

    static long countFamilyXEqY(long limit, int threads) {
        if (limit <= 7)
            return 0;
        long numerator = limit - 1;
        int mMax = (int) Math.sqrt(limit) + 3;

        if (threads <= 1) {
            return countXEqYWorker(1, mMax + 1, limit, numerator);
        }

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Future<Long>> futures = new ArrayList<>();
        int chunk = (mMax + threads) / threads;

        for (int i = 0; i < threads; ++i) {
            final int lo = Math.max(1, i * chunk);
            final int hi = Math.min(mMax + 1, (i + 1) * chunk);
            if (lo >= hi)
                continue;
            futures.add(executor.submit(() -> countXEqYWorker(lo, hi, limit, numerator)));
        }

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

    static long countUEqVWorker(int lo, int hi, long limit, long numerator) {
        long local = 0;
        for (int idx = lo; idx < hi; ++idx) {
            long p = 2L * idx + 1;
            long p2 = p * p;
            for (long q = 1;; ++q) {
                long s = p2 + 2L * p * q + 2L * q * q;
                long denom = 2L * s;
                if (denom >= limit)
                    break;
                if (gcd((int) p, (int) q) == 1) {
                    local += numerator / denom;
                }
            }
        }
        return local;
    }

    static long countFamilyUEqV(long limit, int threads) {
        if (limit <= 13)
            return 0;
        long numerator = limit - 1;
        int pMax = (int) Math.sqrt(limit / 2) + 3;
        int oddCount = (pMax + 1) / 2;

        if (threads <= 1) {
            return countUEqVWorker(0, oddCount, limit, numerator);
        }

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Future<Long>> futures = new ArrayList<>();
        int chunk = (oddCount + threads - 1) / threads;

        for (int i = 0; i < threads; ++i) {
            final int lo = i * chunk;
            final int hi = Math.min(oddCount, (i + 1) * chunk);
            if (lo >= hi)
                continue;
            futures.add(executor.submit(() -> countUEqVWorker(lo, hi, limit, numerator)));
        }

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

    public static String solve() {
        long limit = 100000000L;
        int threads = Runtime.getRuntime().availableProcessors();
        if (threads == 0)
            threads = 1;

        long totalX = countFamilyXEqY(limit, threads);
        long totalU = countFamilyUEqV(limit, threads);

        return String.valueOf(totalX + totalU);
    }

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