// Задача "Обобщенные числа-близнецы"
// 4-ая интернет-олимпиада сезона 2009-2010, базовый уровень
// Автор задачи: Владимир Ульянцев, ulyantsev@rain.ifmo.ru
// Автор решения: Роман Колганов, Roman.Kolganov@gmail.com
// Решето Эратосфена
import java.util.*;
import java.io.*;

public class twins_rk implements Runnable {
	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	public static void main(String[] args) {
		new Thread(new twins_rk()).start();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			String filename = "twins_rk".substring(0, "twins_rk".indexOf('_'));
			in = new BufferedReader(new FileReader(filename + ".in"));
			st = new StringTokenizer("");
			out = new PrintWriter(new File(filename + ".out"));
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(in.readLine());
			} catch (Exception e) {
				throw new Error("Unexpected end of file");
			}
		}
		return st.nextToken();
	}

	private long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	void myAssert(boolean b, String message) {
		if (!b) {
			throw new Error(message);
		}
	}

	long inBounds(long x, long l, long r, String name) {
		myAssert(l <= x && x <= r, name + " is out of bounds: " + x
				+ " is not in [" + l + ", " + r + "]");
		return x;
	}

	final long MAX = (long) 1e6;

	void solve() throws IOException {
		long curTime = System.currentTimeMillis();
		long n = inBounds(nextLong(), 1, MAX, "n");
		long k = inBounds(nextLong(), 1, MAX, "k");
		long[] primes = new long[1000000];
		primes[0] = 2;
		int primecnt = 1;
		int ptwin = 0;
		int res = 0;
		for(int i = 3; i <= n; i += 2) {
			int check = 0;
			while(check < primecnt && primes[check] <= (int) Math.sqrt(i) && i % primes[check] != 0) {
				++check;
			}
			if(check == primecnt || primes[check] > (int) Math.sqrt(i)) {
				primes[primecnt] = i;
				++primecnt;
				while(i - primes[ptwin] > k) {
					++ptwin;
				}
				if(i - primes[ptwin] == k) {
					++res;
				}
			}
		}
		out.println(res);
		System.err.println(System.currentTimeMillis() - curTime);
		System.err.println(primecnt);
	}

}