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

public class Euler295 {
    static long isqrtU64(long n) {
        long x = (long) Math.sqrt(n);
        while ((x + 1) <= n / (x + 1)) {
            ++x;
        }
        while (x > n / x) {
            --x;
        }
        return x;
    }

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

    static class EGResult {
        long x, y, g;

        EGResult(long x, long y, long g) {
            this.x = x;
            this.y = y;
            this.g = g;
        }
    }

    static EGResult extendedGcd(long a, long b) {
        long oldR = a, r = b;
        long oldS = 1, s = 0;
        long oldT = 0, t = 1;

        while (r != 0) {
            long q = oldR / r;
            long nr = oldR - q * r;
            oldR = r;
            r = nr;
            long ns = oldS - q * s;
            oldS = s;
            s = ns;
            long nt = oldT - q * t;
            oldT = t;
            t = nt;
        }
        return new EGResult(oldS, oldT, oldR);
    }

    static int computeThreshold(int a, int b) {
        long aa = a, bb = b;
        long s2 = aa * aa + bb * bb;
        EGResult eg = extendedGcd(aa, bb);

        long x0 = -eg.y;
        long y0 = eg.x;

        long A0 = aa * x0 + bb * y0;
        long r = A0 % s2;
        if (r < 0)
            r += s2;
        if (r > s2 / 2)
            r = s2 - r;

        long quad = (r * r + 1) / s2;
        long M = r - quad;

        long t = (M & 1L) != 0 ? M : M + 1;
        if (t < 1)
            t = 1;
        return (int) t;
    }

    static class Sequence implements Comparable<Sequence> {
        long s2;
        int t, kmax;

        Sequence(long s2, int t, int kmax) {
            this.s2 = s2;
            this.t = t;
            this.kmax = kmax;
        }

        @Override
        public int compareTo(Sequence o) {
            if (this.s2 != o.s2)
                return Long.compare(this.s2, o.s2);
            return Integer.compare(this.t, o.t);
        }
    }

    static class Occurrence implements Comparable<Occurrence> {
        long radius2;
        int sequenceId;

        Occurrence(long r2, int sid) {
            this.radius2 = r2;
            this.sequenceId = sid;
        }

        @Override
        public int compareTo(Occurrence o) {
            if (this.radius2 != o.radius2)
                return Long.compare(this.radius2, o.radius2);
            return Integer.compare(this.sequenceId, o.sequenceId);
        }
    }

    static class IdSetKey {
        int[] ids;
        int len;

        IdSetKey(int capacity) {
            ids = new int[capacity];
            len = 0;
        }

        @Override
        public boolean equals(Object o) {
            IdSetKey that = (IdSetKey) o;
            if (this.len != that.len)
                return false;
            for (int i = 0; i < len; ++i) {
                if (this.ids[i] != that.ids[i])
                    return false;
            }
            return true;
        }

        @Override
        public int hashCode() {
            int h = 0x9e3779b9 ^ len;
            for (int i = 0; i < len; ++i) {
                h ^= ids[i] + 0x9e3779b9 + (h << 6) + (h >> 2);
            }
            return h;
        }

        IdSetKey cloneKey() {
            IdSetKey copy = new IdSetKey(this.ids.length);
            copy.len = this.len;
            System.arraycopy(this.ids, 0, copy.ids, 0, this.len);
            return copy;
        }
    }

    public static String solve() {
        long nLimit = 100000;
        long n2 = nLimit * nLimit;
        int bMax = (int) isqrtU64(2 * nLimit);

        List<Sequence> sequences = new ArrayList<>();
        Set<Long> seen = new HashSet<>();

        for (int a = 1; a <= bMax; a += 2) {
            for (int b = a; b <= bMax; b += 2) {
                if (gcd(a, b) != 1)
                    continue;

                long s2 = (long) a * a + (long) b * b;
                int t = computeThreshold(a, b);

                long ratio = (4 * n2) / s2;
                if (ratio <= 1)
                    continue;

                int kmax = (int) isqrtU64(ratio - 1);
                if ((kmax & 1) == 0)
                    --kmax;
                if (kmax < t)
                    continue;

                long key = (s2 << 32) | (t & 0xFFFFFFFFL);
                if (!seen.add(key))
                    continue;

                sequences.add(new Sequence(s2, t, kmax));
            }
        }
        Collections.sort(sequences);

        List<Occurrence> occurrences = new ArrayList<>();
        for (int sid = 0; sid < sequences.size(); ++sid) {
            Sequence seq = sequences.get(sid);
            for (long k = seq.t; k <= seq.kmax; k += 2) {
                long k2 = k * k;
                long radius2 = (seq.s2 * (1 + k2)) / 4;
                occurrences.add(new Occurrence(radius2, sid));
            }
        }

        Collections.sort(occurrences);

        Map<IdSetKey, Integer> fullSetFrequency = new HashMap<>();
        long distinctRadii = 0;

        int pos = 0;
        while (pos < occurrences.size()) {
            long currentRadius = occurrences.get(pos).radius2;
            IdSetKey key = new IdSetKey(8);

            while (pos < occurrences.size() && occurrences.get(pos).radius2 == currentRadius) {
                int sid = occurrences.get(pos).sequenceId;
                if (key.len == 0 || sid != key.ids[key.len - 1]) {
                    if (key.len >= 8) {
                        key.ids = Arrays.copyOf(key.ids, key.len * 2);
                    }
                    key.ids[key.len++] = sid;
                }
                ++pos;
            }

            ++distinctRadii;
            IdSetKey finalKey = key.cloneKey();
            fullSetFrequency.put(finalKey, fullSetFrequency.getOrDefault(finalKey, 0) + 1);
        }

        Map<IdSetKey, Long> subsetFrequency = new HashMap<>();

        for (Map.Entry<IdSetKey, Integer> entry : fullSetFrequency.entrySet()) {
            IdSetKey full = entry.getKey();
            long freq = entry.getValue();

            int subsetCount = 1 << full.len;
            for (int mask = 1; mask < subsetCount; ++mask) {
                IdSetKey subset = new IdSetKey(full.len);
                for (int bit = 0; bit < full.len; ++bit) {
                    if (((mask >> bit) & 1) != 0) {
                        subset.ids[subset.len++] = full.ids[bit];
                    }
                }
                IdSetKey fSub = subset.cloneKey();
                subsetFrequency.put(fSub, subsetFrequency.getOrDefault(fSub, 0L) + freq);
            }
        }

        long intersectingDistinctPairs = 0;

        for (Map.Entry<IdSetKey, Long> entry : subsetFrequency.entrySet()) {
            long cnt = entry.getValue();
            if (cnt < 2)
                continue;

            long ways = (cnt * (cnt - 1)) / 2;
            if ((entry.getKey().len & 1) != 0) {
                intersectingDistinctPairs += ways;
            } else {
                intersectingDistinctPairs -= ways;
            }
        }

        long answer = distinctRadii + intersectingDistinctPairs;
        return String.valueOf(answer);
    }

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