import java.math.BigInteger;
import java.util.*;

public class Euler180 {
    static BigInteger gcd(BigInteger a, BigInteger b) {
        return a.gcd(b);
    }

    static long[] makeFrac(long n, long d) {
        if (d == 0)
            return null;
        long g = gcd64(n, d);
        return new long[] { n / g, d / g };
    }

    static long gcd64(long a, long b) {
        a = Math.abs(a);
        b = Math.abs(b);
        while (b != 0) {
            long t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    static long[] addFrac(long[] a, long[] b) {
        long g = gcd64(a[1], b[1]);
        long num = a[0] * (b[1] / g) + b[0] * (a[1] / g);
        long den = (a[1] / g) * b[1];
        long h = gcd64(Math.abs(num), Math.abs(den));
        return new long[] { num / h, den / h };
    }

    static long[] mulFrac(long[] a, long[] b) {
        long num = a[0] * b[0], den = a[1] * b[1];
        long g = gcd64(Math.abs(num), Math.abs(den));
        return new long[] { num / g, den / g };
    }

    static long[] sqFrac(long[] f) {
        return mulFrac(f, f);
    }

    static long[] recipFrac(long[] f) {
        return new long[] { f[1], f[0] };
    }

    static long[] divFrac(long[] a, long[] b) {
        return mulFrac(a, recipFrac(b));
    }

    static boolean isSq64(long v) {
        if (v < 0)
            return false;
        long r = (long) Math.sqrt(v);
        return r * r == v || (r + 1) * (r + 1) == v;
    }

    static long[] sqrtFrac(long[] f) {
        long rn = (long) Math.sqrt(f[0]), rd = (long) Math.sqrt(f[1]);
        if (rn * rn == f[0] && rd * rd == f[1])
            return makeFrac(rn, rd);
        rn++;
        if (rn * rn == f[0] && rd * rd == f[1])
            return makeFrac(rn, rd);
        return null;
    }

    static long fracHash(long[] f) {
        return f[0] * 1000000007L + f[1];
    }

    public static void main(String[] args) {
        int order = 35;
        List<long[]> fracs = new ArrayList<>();
        for (long d = 2; d <= order; d++)
            for (long n = 1; n < d; n++)
                if (gcd64(n, d) == 1)
                    fracs.add(new long[] { n, d });
        Set<Long> allowed = new HashSet<>();
        for (long[] f : fracs)
            allowed.add(fracHash(f));

        Set<Long> sums = new HashSet<>();
        for (long[] x : fracs)
            for (long[] y : fracs) {
                // n=1: z = x+y
                long[] z1 = addFrac(x, y);
                if (z1[1] > 0 && allowed.contains(fracHash(z1)))
                    sums.add(fracHash(addFrac(addFrac(x, y), z1)));
                // n=-1: z = xy/(x+y)
                long[] s = addFrac(x, y);
                if (s[0] != 0) {
                    long[] zm1 = divFrac(mulFrac(x, y), s);
                    if (zm1[1] > 0 && allowed.contains(fracHash(zm1)))
                        sums.add(fracHash(addFrac(addFrac(x, y), zm1)));
                }
                // n=2: z^2 = x^2+y^2
                long[] z2sq = addFrac(sqFrac(x), sqFrac(y));
                long[] z2 = sqrtFrac(z2sq);
                if (z2 != null && allowed.contains(fracHash(z2)))
                    sums.add(fracHash(addFrac(addFrac(x, y), z2)));
                // n=-2: 1/z^2 = 1/x^2 + 1/y^2
                long[] ixsq = sqFrac(recipFrac(x)), iysq = sqFrac(recipFrac(y));
                long[] zm2sq = recipFrac(addFrac(ixsq, iysq));
                long[] zm2 = sqrtFrac(zm2sq);
                if (zm2 != null && allowed.contains(fracHash(zm2)))
                    sums.add(fracHash(addFrac(addFrac(x, y), zm2)));
            }

        // Recover fractions from hashes and sum them
        Map<Long, long[]> hashToFrac = new HashMap<>();
        for (long[] x : fracs)
            for (long[] y : fracs) {
                long[][] zCands = new long[4][];
                zCands[0] = addFrac(x, y);
                long[] s = addFrac(x, y);
                zCands[1] = s[0] != 0 ? divFrac(mulFrac(x, y), s) : null;
                long[] z2 = sqrtFrac(addFrac(sqFrac(x), sqFrac(y)));
                zCands[2] = z2;
                long[] zm2 = sqrtFrac(recipFrac(addFrac(sqFrac(recipFrac(x)), sqFrac(recipFrac(y)))));
                zCands[3] = zm2;
                for (long[] z : zCands) {
                    if (z != null && z[1] > 0 && allowed.contains(fracHash(z))) {
                        long[] sv = addFrac(addFrac(x, y), z);
                        long h = fracHash(sv);
                        if (sums.contains(h))
                            hashToFrac.put(h, sv);
                    }
                }
            }

        BigInteger num = BigInteger.ZERO, den = BigInteger.ONE;
        for (long[] f : hashToFrac.values()) {
            BigInteger fn = BigInteger.valueOf(f[0]), fd = BigInteger.valueOf(f[1]);
            num = num.multiply(fd).add(den.multiply(fn));
            den = den.multiply(fd);
            BigInteger g = num.gcd(den);
            num = num.divide(g);
            den = den.divide(g);
        }
        System.out.println(num.add(den));
    }
}
