Cost of Sweets
Submissions: 406   Accuracy:

53.71%

  Difficulty: Medium   Marks: 4

Jeny love Sweets so much. Now she is at famous restaurant and wants to eat M pieces of a particular sweet. Cost of nth sweet can only be determined by the determinant of matrix of order n x n, where n = 1 to M. The (i, j)th term of matrix is given as:

A[i][j]= minimum(i, j) *(-1)((i-1)*n + (j-1)).

Matrix indexes starts with 1. The task is to find the cost of M sweets.

Input: The First line of input contains a integer T, denoting the total number of test cases. Then T test cases follow. Each test case consists of a single line conataining an integer M denoting the number of Sweets.

Output: Print the desired output corresponding to each test case in a separate line.

Constraints:
1<=T<=100
1<=M<=1000000

Example:
INPUT :
2
1
2

OUTPUT:
1
0

EXPLAINATION:

MAtrix of 1*1 is: |1|

Matrix of 2*2 is:  |1 -1|
                           |1 -2|

Determinant of matrix 1x1 = 1

Determinant of matrix 2x2= -1

Cost of 1 sweet = 1
Cost of 2 sweets  = Cost of 1st sweet + Cost of 2nd sweet = 1 + -1 = 0 

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

Contributor: Raju Varshney
Author: Mukesh Kumar 5


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.