Large average

3.5

38 votes
Math Basic, Algorithms, Basic Math, Math
Problem

The average is defined as the sum of all the numbers divided (integer division) by the total numbers that are included to determine the average. Therefore, your task is to determine the average of all naturals number from \(L\) to \(R\) both inclusive.

For example, all the natural numbers from \(L = 3\) to \(R = 8\) are \([3, 4, 5, 6, 7, 8]\), then the average is \((3 + 4 + 5 + 6 + 7 + 8) / 6 = 33 / 6 = 5\).

Input format

  • First line: \(t\) denoting the number of test cases
  • Next \(t\) lines: Two space-separated integers \(L\) and \(R\) as described in the problem statement

Output format

Print \(t\) lines containing a single integer that denotes the required answer.

Constraints

\(1 \leq t \leq 10^5\)

\(0 \leq L \leq R \leq 10^{18}\)

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Refer the example provided in the problem.

Editor Image

?