68. [ CPE ] Lucky Thief

I'm a slow walker, but I never walk backwards.

Task Description
Lucky Thief
A very lucky thief found n keys on a street with m houses. He knows that each key opens exactly one door so he wants to know which door is, but he also wants to do the less number of tries in order to avoid the security systems.
Input Format
The first line contains a single integer, T (T ≤ 100000) indicating the number of test cases. The following T lines contain two integers n and m, 1 ≤ n ≤ m ≤ 100000.
Output Format
Print the minimum number of tries that the thief must perform in order to know what key opens each door with an end of line.
Sample Input

1
2
3
4
3
4 6
1 2
500 900

Sample Output

1
2
3
14
1
324750

Submit

Login

Testdata Set

Download Testdata