import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(read()) def make_prime(U): is_prime = np.zeros(U,np.bool_) is_prime[2] = 1 is_prime[3::2] = 1 M = int(U**.5)+1 for p in range(3,M,2): if is_prime[p]: is_prime[p*p::p+p] = 0 return is_prime, is_prime.nonzero()[0] is_prime, primes = make_prime(3 * N + 10) f = np.zeros(N+1,np.int64) f[primes[primes<=N]] += 1 fft = np.fft.rfft; ifft = np.fft.irfft fft_len = 1 << 19 Ff = fft(f,fft_len); Fg = Ff ** 3; g = ifft(Fg,fft_len) g = np.rint(g).astype(np.int64)[:3*N+1] x = (g * is_prime[:3*N+1]).sum() # a == b や b == c かもしれない状態になっている。うまく間引く。 h = np.zeros(N+N+1,np.int64) h[2*primes[primes<=N]] += 1 Fh = fft(h,fft_len) g = ifft(Ff * Fh, fft_len) g = np.rint(g).astype(np.int64)[:3*N+1] y = (g * is_prime[:3*N+1]).sum() answer = (x - 3 * y) // 6 print(answer)