Easy Sequence Sum
InterviewTime limit2sMemory limit128 MB
Given a sequence where each integer k repeats k times, compute the sum of terms between positions A and B.
- Level
Easy2 of 10
- Topics
- Math, Simulation, Implementation
- Solved
- No attempts yet
Problem
Consider the following sequence. The number 1 appears once, 2 appears twice, 3 appears three times, and in general each positive integer k appears exactly k consecutive times.
1 2 2 3 3 3 4 4 4 4 5 ...
Given an interval [A, B], compute the sum of the terms from the A-th term through the B-th term of this sequence.
Input
The first line contains two integers A and B, the start and end positions of the interval.
1 <= A <= B <= 1,000
Output
Print the sum of the terms in the interval.