This Problem is very straightforward. Let’s define a function where is a permutation of length . Definition of is the minimum number of swaps needed to make the permutation sorted, and you are allowed to swap only adjacent elements.
A permutation is an array of length , consisting of each of the integers from to in some order.
For example, a permutation of length is —
Then we need to do the following operations to sort the permutation —
So we need a total of swap operations to make sorted.
Now you are given an integer . You have to print the total of for all permutations of length . More formally, if we define a set consisting of all permutations of length . Then we need to calculate
Each set of tests contains multiple test cases.
The first line of the input contains a single integer — which represents the number of test cases.
Next, lines of the input contain a single integer — representing the length of the permutation.
For each test case print the case number and a single integer — the total from the problem statement.
Input | Output |
---|---|
4 3 2 4 17 | Case 1: 9 Case 2: 1 Case 3: 72 Case 4: 941220792 |
Consider the first testcase.
For . We have different permutations. And
So is