Under construction

Still being built. Things may change

Primes and XOR? Nonsense

Time limit2sMemory limit1024 MB

Summary
Given L and R up to 1e12, count the integers that can be formed as the XOR of some subset of the primes in [L, R].
Level

Hard8 of 10

Topics
Number theory, Bit manipulation, Math
Solved
No attempts yet

Problem

Define PLR=P∩[L;R]\mathbb{P}_{LR} = \mathbb{P} \cap [L;R], where P\mathbb{P} is the set of prime numbers. In other words, PLR\mathbb{P}_{LR} is the set of all primes between LL and RR inclusive.

Given LL and RR, find the number of integers that can be represented as the XOR of some subset (possibly empty) of PLR\mathbb{P}_{LR}.

Input

The first line contains one integer TT (1≤T≤1001 \le T \le 100), the number of independent test cases. Each of the next TT lines contains two integers LL and RR (2≤L≤R≤10122 \le L \le R \le 10^{12}).

Output

For each test case, print the answer on a separate line.

Hint

In the first example, PLR={2,3,5,7}\mathbb{P}_{LR} = \{2, 3, 5, 7\}.

  • 0=2⊕5⊕70 = 2 \oplus 5 \oplus 7
  • 1=2⊕31 = 2 \oplus 3
  • 2=22 = 2
  • 3=33 = 3
  • 4=3⊕74 = 3 \oplus 7
  • 5=2⊕75 = 2 \oplus 7
  • 6=3⊕56 = 3 \oplus 5
  • 7=77 = 7

In the second example, PLR=∅\mathbb{P}_{LR} = \varnothing, so only 00 can be represented as the XOR of some subset.

Examples1

  1. Example 1

    Input
    3
    2 10
    999999940 1000000000
    2 1000000000000
    
    Expected output
    8
    1
    1099511627776