PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000105. Đếm cặp nguyên tố sinh đôi (Twins)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp nguyên tố sinh đôi (Twins)
Twins
Source: HackerRank
Version: Phuoc Hung OJ Extended
Problem Statement
Lia considers two numbers twins if both are primes and they differ by exactly . Given the inclusive interval , count the pairs whose two members belong to the interval. Reversing the pair does not yield a new pair.
Input
One line contains the interval endpoints .
Output
Print one integer: the number of twin prime pairs entirely inside the interval.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3 13
Output
3
Explanation
There are exactly three pairs in : , , and . Both members of each pair are primes differing by , so the answer is .