Under construction

Still being built. Things may change

Tricknology

Interview

Time limit1sMemory limit1024 MB

Summary
For each query L R, count pairs x < y within [L, R] where the sum of all integers from x to y is prime.
Level

Medium4 of 10

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

Problem

Write a program that performs the following query.

  • L RL\ R: For integers xx and yy that satisfy L≤x<y≤RL \leq x < y \leq R, output the number of integer pairs (x, y)(x, \:y) for which the sum of all natural numbers kk with x≤k≤yx \leq k \leq y is a prime number.

Input

The first line contains the number of queries QQ. (1≤Q≤500 000)(1 \leq Q \leq 500\ 000)

Each of the next QQ lines contains one query, given as two positive integers LL and RR. (2≤L<R≤500 000)(2 \leq L < R \leq 500\ 000)

Output

For each query, print the answer on its own line.

Examples1

  1. Example 1

    Input
    4
    2 4
    3 8
    7 12
    9 21
    
    Expected output
    2
    3
    3
    6