public class Euler273 {
    static final int LIMIT = 150;
    static final int PRIME_COUNT = 16;
    static final int[] PRIMES = {
            5, 13, 17, 29, 37, 41, 53, 61,
            73, 89, 97, 101, 109, 113, 137, 149
    };

    static class Complex {
        long real, imag;

        Complex(long r, long i) {
            real = r;
            imag = i;
        }

        Complex mul(Complex o) {
            return new Complex(real * o.real - imag * o.imag, real * o.imag + imag * o.real);
        }

        Complex conj() {
            return new Complex(real, -imag);
        }
    }

    static Complex[] reps = new Complex[LIMIT];

    static long dfs(int idx, Complex value) {
        if (idx == PRIME_COUNT) {
            long a = Math.abs(value.real);
            long b = Math.abs(value.imag);
            return Math.min(a, b);
        }
        long res = dfs(idx + 1, value);
        res += dfs(idx + 1, value.mul(reps[PRIMES[idx]]));
        res += dfs(idx + 1, value.mul(reps[PRIMES[idx]].conj()));
        return res;
    }

    static void buildRepresentations() {
        for (int i = 1; i * i < LIMIT; i += 2) {
            for (int j = 2; i * i + j * j < LIMIT; j += 2) {
                reps[i * i + j * j] = new Complex(i, j);
            }
        }
    }

    public static String solve() {
        buildRepresentations();
        long sum = 0;
        for (int k = 0; k < PRIME_COUNT; ++k) {
            sum += dfs(k + 1, reps[PRIMES[k]]);
        }
        return String.valueOf(sum);
    }

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