Under construction

Still being built. Things may change

Curiosity

Time limit1sMemory limit128 MB

Summary
For each query [a, b], find the primes in the range in order and compute an alternating sum that triples odd-indexed primes.
Level

Medium5 of 10

Topics
Number theory, Prefix sum, Math, Brute force
Solved
No attempts yet

Problem

Namgyu is a curious person. He built a function FF that takes two integers aa and bb and computes a value from the primes that lie between them.

Let the primes inside the closed interval [a,b][a, b], listed from smallest to largest, be A1<A2<⋯<AnA_1 < A_2 < \dots < A_n. The function F(a,b)F(a, b) multiplies every odd numbered prime by 3 and adds it, then subtracts every even numbered prime as it is.

F(a,b)=3A1−A2+3A3−A4+3A5−A6+…F(a, b) = 3A_1 - A_2 + 3A_3 - A_4 + 3A_5 - A_6 + \dots

The count nn decides the sign of the last term. If nn is odd the sum ends with +3An+3A_n, and if nn is even it ends with −An-A_n.

For example, consider F(3,7)F(3, 7). The primes from 3 to 7 inclusive are 3, 5, and 7, so the value is 3×3−5+3×7=253 \times 3 - 5 + 3 \times 7 = 25.

If the interval holds no prime at all, F(a,b)F(a, b) is 0.

Input

The first line contains the number of questions qq. (1≤q≤1051 \le q \le 10^5)

Each of the next qq lines holds one question as two integers aa and bb separated by a space. (1≤a≤b≤1051 \le a \le b \le 10^5)

Output

For each question, print the value of F(a,b)F(a, b) on its own line, in the order the questions are given.

Examples1

  1. Example 1

    Input
    2
    3 7
    5 7
    
    Expected output
    25
    8