Under construction

Still being built. Things may change

Generalized Twin Primes

Time limit2sMemory limit1024 MB

Summary
Given n and k, count the prime pairs (p, q) with q - p = k and q at most n. The bounds are at most 10^4, so a sieve suffices.
Level

Easy2 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

In number theory, a pair of primes (p,q)(p, q) with q−p=2q - p = 2 is called a twin prime pair. For example, (3,5)(3, 5) and (11,13)(11, 13) are twin prime pairs. A pair of primes (p,q)(p, q) with q−p=kq - p = k, where kk is a positive integer, is called a generalized twin prime pair. For example, for k=4k = 4, the pair (3,7)(3, 7) is a generalized twin prime pair.

It is conjectured that there are infinitely many twin prime pairs, but this has not been proven. Counting the generalized twin prime pairs among all natural numbers for a given kk is at least as hard as the same question for twin primes.

This problem is simpler. Given kk, count the generalized twin prime pairs among the natural numbers from 1 to nn.

Input

The first line contains two natural numbers nn and kk, separated by a space (1≤n,k≤1041 \le n, k \le 10^4).

Output

Print the number of pairs of primes (p,q)(p, q) such that 1≤p<q≤n1 \le p < q \le n and q−p=kq - p = k.

Examples3

  1. Example 1

    Input
    17 2
    
    Expected output
    3
    
  2. Example 2

    Input
    10000 1
    
    Expected output
    1
    
  3. Example 3

    Input
    20 7
    
    Expected output
    0