CF2007A.Dora's Set

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Dora's Set

Dora has a set ss containing integers. In the beginning, she will put all integers in [l,r][l, r] into the set ss. That is, an integer xx is initially contained in the set if and only if lxrl \leq x \leq r. Then she allows you to perform the following operations:

  • Select three distinct integers aa, bb, and cc from the set ss, such that gcd(a,b)=gcd(b,c)=gcd(a,c)=1\gcd(a, b) = \gcd(b, c) = \gcd(a, c) = 1^\dagger.
  • Then, remove these three integers from the set ss.

What is the maximum number of operations you can perform?

^\daggerRecall that gcd(x,y)\gcd(x, y) means the greatest common divisor of integers xx and yy.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t5001 \leq t \leq 500) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers ll and rr (1lr10001 \leq l \leq r \leq 1000) — the range of integers in the initial set.

Output

For each test case, output a single integer — the maximum number of operations you can perform.

Note

In the first test case, you can choose a=1a = 1, b=2b = 2, c=3c = 3 in the only operation, since gcd(1,2)=gcd(2,3)=gcd(1,3)=1\gcd(1, 2) = \gcd(2, 3) = \gcd(1, 3) = 1, and then there are no more integers in the set, so no more operations can be performed.

In the second test case, you can choose a=3a = 3, b=5b = 5, c=7c = 7 in the only operation.

In the third test case, you can choose a=11a = 11, b=19b = 19, c=20c = 20 in the first operation, a=13a = 13, b=14b = 14, c=15c = 15 in the second operation, and a=10a = 10, b=17b = 17, c=21c = 21 in the third operation. After the three operations, the set ss contains the following integers: 1212, 1616, 1818. It can be proven that it's impossible to perform more than 33 operations.

Samples

8
1 3
3 7
10 21
2 8
51 60
2 15
10 26
1 1000
1
1
3
1
2
3
4
250

在线编程 IDE

建议全屏模式获得最佳体验