DMOPC '20 Contest 4 P1 - Missing Numbers

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You are learning how to count in math class today! To demonstrate this invaluable ability, your teacher wrote the first N positive integers on the chalkboard. However, when he went for a quick bathroom break, Jennifer the delinquent took the chance to erase 2 of the numbers on the board! When your teacher returned, he summed up all the remaining numbers on the board and called it S. Naturally, since your teacher is a genius, he did not mess up his calculations when summing up the numbers and S is computationally correct. However, S wasn't exactly the number he expected to get! As the teacher's pet an exemplary student, please help your teacher find the number of possible unordered pairs of numbers Jennifer erased. To ensure the integrity of your solution, there may be up to T test cases.

Constraints

1 \le T \le 100

2 \le N \le 10^9

0 \le S \le 10^{18}

Subtask 1 [10%]

2 \le N \le 10^3

Subtask 2 [20%]

2 \le N \le 10^5

Subtask 3 [70%]

No additional constraints.

Input Specification

The first line contains an integer T, the number of test cases. The next T lines describe the test cases.

The first and only line of each test case contains 2 integers N and S, as specified in the problem statement.

Output Specification

For each test case output one integer on its own line, the number of possible unordered pairs of numbers Jennifer erased.

Sample Input

2
5 9
2 0

Sample Output

2
1

Explanation

For the first test case, your teacher initially wrote the numbers 1, 2, 3, 4, 5 on the board. After Jennifer erased 2 numbers, the remaining sum is 9. There are 2 possible unordered pairs of numbers Jennifer could've erased, namely (1, 5) leaving 2, 3, 4, or (2, 4) leaving 1, 3, 5.

For the second test case, the only possibility is that Jennifer erased 1 and 2 since those are the only numbers on the board, so the answer is 1.


Comments

There are no comments at the moment.