import java.math.BigInteger;

public class Euler281 {
    static final long LIMIT = 1000000000000000L;

    static int[] computeTotients(int nMax) {
        int[] phi = new int[nMax + 1];
        for (int i = 0; i <= nMax; ++i)
            phi[i] = i;

        for (int p = 2; p <= nMax; ++p) {
            if (phi[p] == p) {
                for (int multiple = p; multiple <= nMax; multiple += p) {
                    phi[multiple] -= phi[multiple] / p;
                }
            }
        }
        return phi;
    }

    static BigInteger centralBinomial(int n) {
        BigInteger c = BigInteger.ONE;
        for (int i = 1; i <= n; ++i) {
            c = c.multiply(BigInteger.valueOf(n + i))
                    .divide(BigInteger.valueOf(i));
        }
        return c;
    }

    static int computeNUpperBound(long limit) {
        BigInteger limitBig = BigInteger.valueOf(limit);
        int n = 1;
        int best = 0;
        while (true) {
            BigInteger bound = centralBinomial(n).divide(BigInteger.valueOf(2L * n));
            if (bound.compareTo(limitBig) > 0)
                break;
            best = n;
            ++n;
        }
        return best;
    }

    static int computeMUpperBound(long limit) {
        BigInteger limitBig = BigInteger.valueOf(limit);
        BigInteger factorial = BigInteger.ONE;
        int best = 1;
        for (int m = 2;; ++m) {
            if (factorial.compareTo(limitBig) > 0)
                break;
            best = m;
            factorial = factorial.multiply(BigInteger.valueOf(m));
        }
        return best;
    }

    static BigInteger[] factorialsUpTo(int nMax) {
        BigInteger[] fact = new BigInteger[nMax + 1];
        fact[0] = BigInteger.ONE;
        for (int i = 1; i <= nMax; ++i) {
            fact[i] = fact[i - 1].multiply(BigInteger.valueOf(i));
        }
        return fact;
    }

    static BigInteger[][] precomputeFactPowers(BigInteger[] fact, int nMax, int mMax) {
        BigInteger[][] powers = new BigInteger[nMax + 1][mMax + 1];
        for (int n = 0; n <= nMax; ++n) {
            powers[n][0] = BigInteger.ONE;
            for (int m = 1; m <= mMax; ++m) {
                powers[n][m] = powers[n][m - 1].multiply(fact[n]);
            }
        }
        return powers;
    }

    static BigInteger fValue(int m, int n, int[] phi, BigInteger[] fact, BigInteger[][] factPowers) {
        int total = m * n;
        BigInteger sum = BigInteger.ZERO;

        for (int l = 1; l <= n; ++l) {
            if (n % l != 0)
                continue;

            int slice = n / l;
            BigInteger numerator = fact[total / l];
            BigInteger denominator = factPowers[slice][m];
            BigInteger multinomial = numerator.divide(denominator);

            sum = sum.add(multinomial.multiply(BigInteger.valueOf(phi[l])));
        }

        return sum.divide(BigInteger.valueOf(total));
    }

    public static String solve() {
        int nUpper = computeNUpperBound(LIMIT);
        int mUpper = computeMUpperBound(LIMIT);

        int maxFactorialNeeded = mUpper * nUpper;
        BigInteger[] fact = factorialsUpTo(maxFactorialNeeded);
        int[] phi = computeTotients(nUpper);
        BigInteger[][] factPowers = precomputeFactPowers(fact, nUpper, mUpper);

        BigInteger limitBig = BigInteger.valueOf(LIMIT);
        long answer = 0;

        for (int m = 2; m <= mUpper; ++m) {
            for (int n = 1; n <= nUpper; ++n) {
                BigInteger value = fValue(m, n, phi, fact, factPowers);
                if (value.compareTo(limitBig) <= 0) {
                    answer += value.longValue();
                }
            }
        }

        return String.valueOf(answer);
    }

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