Gadget fan
Practice
4 (5 votes)
Approved
Combinatorics
Easy
Math
Problem
40% Success 5577 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

iMagine yourself as a loyal fan of one popular company that creates all kind of gadgets. After all of these years "that company" has created n different mobile phones, enumerated from 1 to n and powering devices, enumerated the same way. Due to the production policy, phones can be charged only by devices with phone's version not exceeding charger's version. Moreover, phone's and device's total version has to be equal or less than k. For example, if phone's version is a and charger's is b, then the phone can be charged if \(a \le b\) and \(a + b \le k\).

You are so loyal, you have already bought every device — all n phones and n chargers! Moreover, you are fond of tea and taking photos with your cool mug, but with your effort phone discharges in a couple of hours, and you have to take a phone and a charger with you to the tea-shop and, of course, a pair of different ones.

Your task is to find the number of days, you can visit the tea-shop with a different pair of phone and a charger, which you haven't brought before, so that you can charge the phone, according to the rules mentioned above.

Input format

The first line of input contains one integer t — number of test cases.

For each case, single line contains two integers n and k — number of mobile phones and versions' maximum sum, respectively.

Constraints

\(1 \le t \le 10000\)

\( 1 \le n, k \le 2 \cdot 10^9 \)

Output format

For each case, output on a separate line a single integer — number of different pairs of a phone and a charger, satisfying the rules described in the statement.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
CombinatoricsEasyInclusion-ExclusionMath
Points:30
3 votes
Tags:
CombinatoricsEasyGraphsInclusion-ExclusionMath