The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
q1
A rank list is a list of ranks of persons in a programming contest. Note that some of the persons might be having same rank. {1, 2}, {1, 2, 2} and {1, 1, 2, 3, 4, 4} are few examples of rank lists whereas {1, 3}, {0, 2}, {1, 2, 4} are not rank lists.
Also note that a rank list need not to be sorted e.g. {2, 2, 1} and {3, 3, 2, 1} are valid rank lists.
Mathematically, a rank list is an array of numbers when sorted will have the starting element as 1 and difference between any two consecutive elements less than or equal to 1.
A rank list is said to be an ideal rank list if no two persons gets equal rank in it.
You can convert any rank list into an ideal rank list by applying following operations. In a single operation, you can change value of any one element of the rank list to any value.
Chandan now wonders about minimum number of operations needed to convert a rank list of size n with sum of its element equal to s in to an ideal rank list. Please help Chandan find this minimum number of operations needed to create an ideal rank list.
Note that you are guaranteed that values of n, s will be given in such a way that there will exist a valid rank list.
First line of input will give an integer T denoting number of test cases.
Then for next T lines, each line will contain two space separated integers n, s.
For each test case, print a single line containing a single integer corresponding to the answer of the problem.
Input: 4 1 1 3 6 3 5 3 3 Output: 0 0 1 2
Example case 1.
Only possible rank list in this case is {1}, As it is already an ideal rank list, hence you need zero operations.
Example case 2.
Only possible rank list in this case is {1 2 3}, As it is already an ideal rank list, hence you need zero operations.
Example case 3.
One of the possible rank list is {1 2 2}, You can convert it into an ideal rank list by changing any 2 to 3 i.e. {1, 2, 3}, hence you need one operations.
Example case 4.
Only possible rank list is {1 1 1}, You can convert it into an ideal rank list by changing a 1 to 2 and another 1 to 3 i.e. {1, 2, 3}, hence you need two operations.
q2
For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x).
"k!" means factorial: k! = 1 * 2 * .. * k
Chef wants to calculate F(p1) + F(p2) + ... + F(pn).
As answer could be large, help him, calculate value modulo m.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll