This page is still under construction.

Parts of this page are still being built. What you see may change.

Primes

Time limit8sMemory limit256 MB

Summary
Answer online queries that ask for the sum of shared distinct prime counts over all pairs in a range [a, b] up to 10^6.
Level

Hard8 of 10

Topics
Number theory, Prefix sum, Math, Implementation
Solved
No attempts yet

Problem

This is an interactive problem.

For two positive integers x,yx,y, define π(x,y)\pi(x,y) as the number of distinct primes that divide both xx and yy. For example, π(2,3)=0\pi(2,3)=0, π(8,16)=1\pi(8,16)=1, and π(30,105)=2\pi(30,105)=2.

For two positive integers a,ba,b with a≤ba\leq b, define S(a,b)S(a,b) as the sum of π(x,y)\pi(x,y) over all pairs of integers (x,y)(x,y) satisfying a≤x<y≤ba\leq x < y\leq b.

Your task is to compute S(a,b)S(a,b) for many query pairs (a,b)(a,b). All queries must be answered online.

Input

The first line contains a single integer qq (1≤q≤5⋅1041\leq q\leq 5\cdot 10^4), the number of queries. The next qq lines describe the queries. The ii-th of these lines contains two integers a_i,b_ia\_i,b\_i (1≤a_i≤b_i≤1061\leq a\_i\leq b\_i\leq 10^6).

The ii-th query (i≥2i\geq 2) is available in the input only after you output the answer to the (i−1)(i-1)-th query.

Output

Print exactly qq lines. The ii-th line must contain the value S(a_i,b_i)S(a\_i,b\_i).

Flush the output after answering each query.

Examples1

  1. Example 1

    Input
    4
    1 5
    6 6
    3 9
    1 500000
    
    Expected output
    1
    0
    6
    56529651093