#P8762. [蓝桥杯 2021 国 ABC] 123

[蓝桥杯 2021 国 ABC] 123

Problem Description

Xiao Lan found an interesting sequence. The first few terms are as follows:

1,1,2,1,2,3,1,2,3,4,1,1,2,1,2,3,1,2,3,4,\ldots

Xiao Lan noticed that the first 11 term of this sequence is the integer 11. The next 22 terms are the integers from 11 to 22. The next 33 terms are the integers from 11 to 33. The next 44 terms are the integers from 11 to 44, and so on.

Xiao Lan wants to know the sum of a consecutive segment in this sequence.

Input Format

The first line contains an integer TT, which indicates the number of queries.

The next TT lines each contain one query. In the ii-th line, there are two integers lil_{i} and rir_{i}, meaning the query asks for the sum from the lil_{i}-th number to the rir_{i}-th number in the sequence.

Output Format

Output TT lines. Each line contains one integer representing the answer to the corresponding query.

3
1 1
1 3
5 8
1
4
8

Hint

For 10%10\% of the testdata, 1T301 \leq T \leq 30, 1liri1001 \leq l_{i} \leq r_{i} \leq 100.

For 20%20\% of the testdata, 1T1001 \leq T \leq 100, 1liri10001 \leq l_{i} \leq r_{i} \leq 1000.

For 40%40\% of the testdata, 1T10001 \leq T \leq 1000, 1liri1061 \leq l_{i} \leq r_{i} \leq 10^{6}.

For 70%70\% of the testdata, 1T100001 \leq T \leq 10000, 1liri1091 \leq l_{i} \leq r_{i} \leq 10^{9}.

For 80%80\% of the testdata, 1T10001 \leq T \leq 1000, 1liri10121 \leq l_{i} \leq r_{i} \leq 10^{12}.

For 90%90\% of the testdata, 1T100001 \leq T \leq 10000, 1liri10121 \leq l_{i} \leq r_{i} \leq 10^{12}.

For all testdata, 1T1000001 \leq T \leq 100000, 1liri10121 \leq l_{i} \leq r_{i} \leq 10^{12}.

Lanqiao Cup 2021 National Contest Group A Problem E (Group B Problem F, Group C Problem F).

Translated by ChatGPT 5