Large average
Practice
3.5 (38 votes)
Math basic
Algorithms
Basic math
Math
Problem
89% Success 9422 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code
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}\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
3 votes
Tags:
Basics of ImplementationMathBasic MathBasic Programming
Points:10
Tags:
Basic MathMathC++
Points:10
29 votes
Tags:
Very-Easy
Editorial