Primes and XOR? Nonsense

시간 제한2초메모리 제한1024 MB

요약
[L, R] 구간 소수들의 부분집합 XOR로 만들 수 있는 정수의 개수를 센다. R은 10^12까지 커질 수 있다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 비트 연산, 조합론
정답자
아직 제출이 없습니다

문제

Define P_LR=P∩\[L;R]\mathbb{P}\_{LR} = \mathbb{P} \cap \[L;R], where P\mathbb{P} is the set of prime numbers. In other words, P_LR\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 XOR of some (possibly empty) subset of P_LR\mathbb{P}\_{LR}.

입력

The first line of input contains one integer TT (1≤T≤1001 \le T \le 100) --- the number of independent test cases you need to process. Descriptions of TT test cases follow.

The description of one test case consists of two integers LL and RR (2≤L≤R≤10122 \le L \le R \le 10^{12}).

출력

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

힌트

In the first example, P_LR=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, P_LR=∅\mathbb{P}\_{LR} = \varnothing, so only 00 can be represented as XOR of some subset.

예제1

  1. 예제 1

    입력
    3
    2 10
    999999940 1000000000
    2 1000000000000
    
    예상 출력
    8
    1
    1099511627776