from itertools import chain from scipy.signal import fftconvolve import numpy as np def convolve(A, B): sz = len(A) + len(B) fft_len = 1 << (sz-1).bit_length() F1 = np.fft.rfft(A, fft_len) F2 = np.fft.rfft(B, fft_len) G = F1 * F2 res = np.fft.irfft(G, fft_len) return np.rint(res + 0.001).astype(np.int64)[:sz - 1] def prime_set(N): """ Nまでの素数のsetを返す """ if N < 4: return ({}, {}, {2}, {2, 3})[N] Nsq = int(N ** 0.5 + 0.5) + 1 primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6))) for i in range(5, Nsq, 2): if i in primes: primes -= set(range(i * i, N + 1, i * 2)) return primes N = int(input()) U = 100000 P = np.array(list(prime_set(3 * U + 1)), dtype=np.int32) primes = P[P <= N] F = np.bincount(1 * primes).astype(np.int64) G = np.bincount(2 * primes).astype(np.int64) H = np.bincount(3 * primes).astype(np.int64) FFF = convolve(F, convolve(F, F)) FG = convolve(F, G) cnt = (FFF - 3 * FG + 2 * H) // 6 print(cnt[P[P < len(cnt)]].sum())