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}\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
1.King Duo
Points:10
1 votes
Tags:
Basic MathAlgorithmsMath
Points:10
11 votes
Tags:
Very-Easy
Points:10
79 votes
Tags:
MathematicsBasic MathVery-EasyMathematics
Editorial
Login to unlock the editorial