Generalized Twin Primes
Time limit2sMemory limit1024 MB
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 with is called a twin prime pair. For example, and are twin prime pairs. A pair of primes with , where is a positive integer, is called a generalized twin prime pair. For example, for , the pair 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 is at least as hard as the same question for twin primes.
This problem is simpler. Given , count the generalized twin prime pairs among the natural numbers from 1 to .
Input
The first line contains two natural numbers and , separated by a space ().
Output
Print the number of pairs of primes such that and .