Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 3 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 16 Sep 2017 My Price 9.00

programming contest.

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.

Input

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.

Output

For each test case, print a single line containing a single integer corresponding to the answer of the problem.

Constraints

  • 1 = T = 10
  • 1 = n = 10^5
  • 1 = s = 10^10

Example

Input: 4 1 1 3 6 3 5 3 3 Output: 0 0 1 2

Explanation

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.

Input

  • First line contains two integers n and m.
  • Next line contains n space separated integers pi.

Output

  • Output a single line containing one integer --- calculated value modulo m.

Constraints

  • 1 = n = 105
  • 1 = pi = 1018
  • 1 = m = 107

Subtasks

  • Subtask #1: 1 = pi = 6 (10 points)
  • Subtask #2: 1 = pi = 7 * 103 (25 points)
  • Subtask #3: m - prime number (25 points)
  • Subtask #4: original constraints (40 points)

Example

Input: 5 7 1 2 3 4 5 Output: 6

Explanation

  • F(1) = 1 * (1! + 1) = 2
  • F(2) = 1 * (1! + 2) + 2 * (2! + 2) = 3 + 8 = 11
  • F(3) = 1 * (1! + 3) + 2 * (2! + 3) + 3 * (3! + 3) = 4 + 10 + 27 = 41
  • F(4) = 1 * (1! + 4) + 2 * (2! + 4) + 3 * (3! + 4) + 4 * (4! + 4) = 5 + 12 + 30 + 112 = 159
  • F(5) = 1 * (1! + 5) + 2 * (2! + 5) + 3 * (3! + 5) + 4 * (4! + 5) + 5 * (5! + 5) = 794
F(1) + F(2) + F(3) + F(4) + F(5) = 2 + 11 + 41 + 159 + 794 = 1007 1007 modulo 7 = 6

Answers

(5)
Status NEW Posted 16 Sep 2017 02:09 PM My Price 9.00

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

Not Rated(0)