Gaurav and Rearrangements
Gaurav loves rearranging digits. Today it’s Gaurav’s birthday so his friend Kunal has given him a task to keep him happy and engaged. He is given N digits (not necessarily unique). Gaurav has to find the sum of all numbers obtained by rearranging the given digits taken all at a time. In other words, Gaurav has to find the sum of all N digit numbers obtained from the digits. Also, if two or more digits are same, their arrangements would be considered different even though rearranging them would result in same number (eg- If the digits are 1,1 then there would be two arrangements 11 and 11 and the sum would be 22).
The first line of input contains T, the number of test cases. For each test case there would be two lines of input. The first line will have N, number of digits. The following line will have N space separated digits. A digit could be any digit from 1 to 9 (0 is excluded).
For each test case output a single line containing the sum of all the arrangements.
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 10
Input: 2 2 1 2 3 1 2 3 Output: 33 1332
Example case 1: Given digits are 1 and 2, different arrangements are 12 and 21 and their sum is 33.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions