#K84057. Sum of Twist Numbers

    ID: 36334 Type: Default 1000ms 256MiB

Sum of Twist Numbers

Sum of Twist Numbers

In this problem, you are given a positive integer (n) and you need to compute the sum of all twist numbers. A twist number for a given (n) is defined as the sum of all numbers formed by permuting the digits (1, 2, \dots, n). For example, when (n = 2), the digits are 1 and 2. The two permutations are 12 and 21, and their sum is (12 + 21 = 33). Similarly, for (n = 3), the three digits are 1, 2, and 3; and the sum of all six possible numbers is (1332).


A mathematical formula can be derived for this problem. The sum can be computed in (O(n)) time per test case using the formula: [ \text{sum} = (n-1)! \times \left(\frac{n(n+1)}{2}\right) \times \left(\frac{10^n-1}{9}\right), ] where ((n-1)!) is the factorial of (n-1).

inputFormat

The input is given via standard input (stdin). The first line contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains a single integer (n) ((1 \le n)), indicating the number of digits. For each test case, you need to compute the sum of all twist numbers for the given (n).

outputFormat

For each test case, output a single line containing the sum of all twist numbers for the given (n) via standard output (stdout).## sample

2
2
3
33

1332

</p>