import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(read()) U = 5 * 10**5 is_prime = np.zeros(U,np.bool) is_prime[2] = 1 is_prime[3::2] = 1 for p in range(3,U,2): if p*p > U: break if is_prime[p]: is_prime[p*p::p+p] = 0 primes = np.where(is_prime)[0] answer = 0 # (p,q,2) if N >= 2: answer += 1 # (2,p,r) and (p,2,r) primes = primes[primes <= N] primes = primes[1:] r = primes[primes**2 - 2 <= N] answer += 2 * is_prime[r**2 - 2].sum() print(answer)