A twin-prime pair is a pair of primes that differ by exactly 2, such as (3, 5) or (11, 13). Given an upper bound n, count how many twin-prime pairs (p, p+2) exist where both p and p+2 are at most n.
A single line with one integer n.
A single integer: the number of twin-prime pairs whose larger member does not exceed n.
Example 1
Input
10
Expected
2
Explanation
The twin pairs with both members at most 10 are (3,5) and (5,7), so the answer is 2.
Example 2
Input
1
Expected
0
Explanation
There are no primes at most 1, so there are no twin-prime pairs.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →