import java.util.*;

public class Euler278 {
    static List<Integer> primesBelow(int limit) {
        boolean[] isPrime = new boolean[limit];
        Arrays.fill(isPrime, true);
        if (limit > 0)
            isPrime[0] = false;
        if (limit > 1)
            isPrime[1] = false;

        for (int p = 2; p * p < limit; ++p) {
            if (!isPrime[p])
                continue;
            for (int x = p * p; x < limit; x += p) {
                isPrime[x] = false;
            }
        }

        List<Integer> primes = new ArrayList<>();
        for (int p = 2; p < limit; ++p) {
            if (isPrime[p]) {
                primes.add(p);
            }
        }
        return primes;
    }

    static long frobeniusSemiprimeTriple(long p, long q, long r) {
        return 2L * p * q * r - p * q - p * r - q * r;
    }

    public static String solve() {
        int primeLimit = 5000;
        List<Integer> primes = primesBelow(primeLimit);
        int n = primes.size();

        // 128-bit emulation for summing large numbers is necessary if the sum exceeds
        // Long.MAX_VALUE.
        // However, max prime is 5000.
        // There are ~669 primes. Number of combinations is (669 choose 3) ~ 50,000,000
        // Average value of frobenius is 2 * p * q * r where p,q,r <= 5000.
        // Max value is 2 * 5000^3 = 2.5e11
        // Expected sum: 2.5e11 * 5e7 = 1.25e19, which fits in an unsigned 64-bit int,
        // but Long.MAX_VALUE is 9e18. So it will overflow a signed long!
        // Wait, the output from C++ is 1228215747273908452.
        // Does 1228215747273908452 fit in a signed long?
        // 1.22e18 fits safely in a signed 64-bit int (Long.MAX_VALUE is 9.22e18).

        long answer = 0;
        for (int i = 0; i < n; ++i) {
            long p = primes.get(i);
            for (int j = i + 1; j < n; ++j) {
                long q = primes.get(j);
                for (int k = j + 1; k < n; ++k) {
                    long r = primes.get(k);
                    answer += frobeniusSemiprimeTriple(p, q, r);
                }
            }
        }
        return String.valueOf(answer);
    }

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