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


  • 1
    Brian_Li23  commented on March 15, 2021, 11:18 a.m. edit 2

    Could anyone who completed this question explain why I might be getting case #5 of batch 3 wrong? Is there something I'm not accounting for? (My submission: https://dmoj.ca/src/3489859)

    Edit: Fixed


    • 0
      ASDAN149A  commented on March 16, 2021, 7:29 a.m. edited

      Could you please tell me how you fixed it? I'm stuck at branch 3 #5 too

      Edit: Fixed too.


  • -13
    Xoniterfos  commented on March 15, 2021, 12:20 a.m.

    This comment is hidden due to too much negative feedback. Click here to view it.