#P8762. Summing Segments in a Structured Sequence

    ID: 21926 Type: Default 1000ms 256MiB

Summing Segments in a Structured Sequence

Summing Segments in a Structured Sequence

Consider the following sequence:

\(1, 1,2, 1,2,3, 1,2,3,4, \ldots\)

The sequence is constructed in blocks. The first block consists of 1 number: \(1\). The second block contains two numbers: \(1, 2\). The third block contains three numbers: \(1, 2, 3\). The fourth block contains four numbers: \(1, 2, 3, 4\), and so on.

Given two positive integers \(L\) and \(R\) (with \(L \le R\)), where the positions in the sequence are 1-indexed, your task is to compute the sum of the elements from the \(L\)-th to the \(R\)-th element (inclusive).

Input/Output Note: The input represents the endpoints of the segment in the sequence and you should output their sum.

inputFormat

The input consists of a single line containing two space-separated integers \(L\) and \(R\) (\(1 \le L \le R\)).

outputFormat

Output a single integer representing the sum of all sequence elements from the \(L\)-th to the \(R\)-th (inclusive).

sample

1 1
1