Distinct Pair Sums CodeChef Solution

Problem 

You are given a range of integers \{L, L+1, \ldots, R\}. An integer X is said to be reachable if it can be represented as a sum of two not necessarily distinct integers in this range. Find the number of distinct reachable integers.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers L and R.

Output

For each test case, print a single line containing one integer — the number of reachable integers.

Constraints

  • 1 \leq T \leq 10^5
  • 1 \leq L \leq R \leq 10^6

Sample 1:

Input
Output
2
2 2
2 3
1
3

Explanation:

Example case 1: The only reachable integer is 2 + 2 = 4.

Example case 2: 45 and 6 are reachable, since 2+2=42+3=5 and 3+3=6.

ANSWER


Post a Comment (0)
Previous Post Next Post