import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== // エラトステネスの篩(ふるい) → 素数の表を作る(大体 O(N) らしい) boolean[] arr = new boolean[500100]; // 初期値 false(素数なら false となる) void eratosthenes(long n){ arr[0] = arr[1] = true; // 素数でない for(int i = 2; i * i <= n; i++){ if( !arr[i] ) { for(int j = i + i; j <= n; j += i){ // j は i の倍数となる arr[j] = true; // i の倍数は素数でない } } } } Set setR = new TreeSet<>(); Set setP = new TreeSet<>(); public void solve() { long N = Integer.parseInt(sc.next()); eratosthenes(N); for (int i = 0; i * i <= 2*N; i++) { if(!arr[i]) setR.add(i); } for (int i = 0; i <= N; i++) { if(!arr[i]) setP.add(i); } int cnt = 0; long wk; for (int r : setR) { wk = (long)r * r; for (int p : setP) { if(wk - p > N) continue; if(wk - p < p) break; if(wk - p == p) cnt++; else if(setP.contains((int)(wk - p))) cnt += 2; } } out.println(cnt); } // ================================================================== }