Summed Matrix
Submissions: 1339   Accuracy:

28.37%

  Difficulty: Easy   Marks: 2

A matrix is constructed of size n*n. such that Mi,j= i+j.
Count the number of cells having value q.

Assume, 1 based indexing.

Input:
The first line contains an integer
, the number of tescases.
Then each test case contains an integer n-
size of the matrix , q- whose count you need to tell.
 

Output:
For every 
testcase, Output the count of q.
 

Constraints:
1<=T<=100
1<=n<=1000000000000000
2<=q<=2*n

Example:
Input:

2
4 7
5 4

Output:
6
3


Explanation:
1st 
testcase- Matrix becomes
2 3 4 5 
3 4 5 6 
4 5 6 7 
5 6 7 8

The count of 7 is 2

2nd testcase-Matrix becomes
2 3 4 5 6 
3 4 5 6 7 
4 5 6 7 8 
5 6 7 8 9 
6 7 8 9 10 
The count of 4 is 3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Abhinav Jain(iamabjain)
Author: iamabjain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.