Differences of the permutations

3.8

80 votes
Basic Programming, Basic Math, Math Basic, Math
Problem

Given an integer N. Consider all the possible permutations p[ ] of all integers from 1 to N. Calculate the value of X for each permutation : 

X=i=1i=NNp[i]

Determine the sum of all X for all possible permutations.

Input format

  • First line: A single integer T denoting the number of test cases
  • Second line: A single integer N.

Output format

 For each test case, print a single line containing the answer.

Constraints

1T5

1N10

Sample Input
1
2
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are 2 possible permutations for N = 2 : p = [1, 2] and p = [2, 1].

For first permutation X = (2 - 1) + (2 - 2) = 1.

For second permutation X = (2 - 2) + (2 - 1) = 1.

So sum of X over 2 possible permutations = 2.

Editor Image

?