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

Bài tập thuộc lộ trình

1 lộ trình

Đế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 22. Given the inclusive interval [L,R][L,R], count the pairs (p,p+2)(p,p+2) whose two members belong to the interval. Reversing the pair does not yield a new pair.

Input

One line contains the interval endpoints L,RL,R.

Output

Print one integer: the number of twin prime pairs entirely inside the interval.

Subtasks

  • Subtask 1 (20 points): 1≤L≤R≤100001\le L\le R\le 10000; 1≤R−L+1≤2001\le R-L+1\le 200.
  • Subtask 2 (30 points): 1≤L≤R≤100000001\le L\le R\le 10000000; 1≤R−L+1≤100001\le R-L+1\le 10000.
  • Subtask 3 (50 points): 1≤L≤R≤10000000001\le L\le R\le 1000000000; 1≤R−L+1≤10000001\le R-L+1\le 1000000.

Examples

Input

3 13

Output

3

Explanation

There are exactly three pairs in [3,13][3,13]: (3,5)(3,5), (5,7)(5,7), and (11,13)(11,13). Both members of each pair are primes differing by 22, so the answer is 33.