PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000099. Đếm số nguyên tố qua nhiều truy vấn (Số nguyên tố (OLP 10 - 2019))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm số nguyên tố qua nhiều truy vấn (Số nguyên tố (OLP 10 - 2019))

Số nguyên tố (OLP 10 - 2019)

Source: LQDOJ

Version: Phuoc Hung OJ Extended

Problem Statement

A mathematician has TT questions. Question ii asks how many prime numbers belong to the inclusive interval [Li,Ri][L_i,R_i]. A prime is an integer greater than 11 having exactly two positive divisors. Answer all questions in their original order.

Input

The first line contains TT. Each of the next TT lines contains Li,RiL_i,R_i for question ii.

Output

Print TT lines. Line ii is the count of primes in [Li,Ri][L_i,R_i].

Subtasks

  • Subtask 1 (20 points): 1≤T≤51\le T\le 5; 1≤Li≤Ri≤100001\le L_i\le R_i\le 10000; ∑i=1T(Ri−Li+1)≤200\sum_{i=1}^T(R_i-L_i+1)\le 200.
  • Subtask 2 (30 points): 1≤T≤1001\le T\le 100; 1≤Li≤Ri≤100000001\le L_i\le R_i\le 10000000; ∑i=1T(Ri−Li+1)≤10000\sum_{i=1}^T(R_i-L_i+1)\le 10000.
  • Subtask 3 (50 points): 1≤T≤10001\le T\le 1000; 1≤Li≤Ri≤10000000001\le L_i\le R_i\le 1000000000; ∑i=1T(Ri−Li+1)≤1000000\sum_{i=1}^T(R_i-L_i+1)\le 1000000.

Examples

Input

2
1 50
10000000 10000050

Output

15
1

Explanation

The interval [1,50][1,50] has 1515 primes: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,472,3,5,7,11,13,17,19,23,29,31,37,41,43,47. The interval [10000000,10000050][10000000,10000050] contains only one prime, 1000001910000019. Hence the answers are 1515 and 11.