import java.util.HashMap;

public class Euler786 {

    static long calcLatticeCount(long a, long b, long c) {
        if (a < b) {
            long temp = a;
            a = b;
            b = temp;
        }
        if (a > c)
            return 0;

        long m = c / a;
        if (a == b)
            return m * (m - 1) / 2;

        long k = (a - 1) / b;
        long h = (c - a * m) / b;

        return calcLatticeCount(b, a - b * k, c - b * (k * m + h)) +
                k * m * (m - 1) / 2 +
                m * h;
    }

    static class MertensCache {
        HashMap<Long, Long> memo;

        MertensCache() {
            memo = new HashMap<>(); // Using primitive maps like fastutil's Long2LongOpenHashMap would be faster,
                                    // but this is standard Java
            memo.put(0L, 0L);
            memo.put(1L, 1L);
        }

        long mertens(long n) {
            if (n <= 1)
                return n;

            Long cached = memo.get(n);
            if (cached != null)
                return cached;

            long z = 1;
            long f = (long) Math.sqrt(n);
            long lim = n / (f + 1);

            for (long i = 1; i <= lim; i++) {
                long c = n / i;
                if (c < n) {
                    z -= mertens(c);
                }
            }

            for (long i = f; i >= 1; i--) {
                long a = n / (i + 1) + 1;
                long b = n / i;
                long c = i;
                if (c < n) {
                    z -= mertens(c) * (b - a + 1);
                }
            }

            memo.put(n, z);
            return z;
        }

        long mertensNotMult3(long n) {
            long z = 0;
            while (n > 0) {
                z += mertens(n);
                n /= 3;
            }
            return z;
        }
    }

    static long solveAlt(long N) {
        MertensCache mc = new MertensCache();
        long z = 0;

        long n = 3L * N + 6L;
        long f = (long) Math.sqrt(n);
        long lim = n / (f + 1);

        for (long i = 1; i <= lim; i++) {
            long g = n / i;
            long q = calcLatticeCount(18, 10, g) - calcLatticeCount(18, 30, g);
            if (q == 0)
                break;
            z += (mc.mertensNotMult3(i) - mc.mertensNotMult3(i - 1)) * q;
        }

        for (long i = f; i >= 1; i--) {
            long a = n / (i + 1) + 1;
            long b = n / i;
            long g = i;
            long q = calcLatticeCount(18, 10, g) - calcLatticeCount(18, 30, g);
            if (q == 0)
                break;
            z += (mc.mertensNotMult3(b) - mc.mertensNotMult3(a - 1)) * q;
        }

        return 4L * z + 2L;
    }

    public static String solve() {
        return Long.toString(solveAlt(1000000000L));
    }

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