# A five-digit number is formed using digits 1, 3, 5, 7 and 9 without repeating any one of them. What is the sum of all such possible numbers?

I have solved the above question but I found another method for it on a website but didn't understand.

Alternative method:

The sum of all the numbers formed by the digits a1, a2, a3,……….an, without repetition of the digits is given by:

(n-1)!(a1 + a2 + a3 + ………an) (10n -1)/9

Hence, the sum of the given numbers = 4!(1 + 3 + 5 + 7 + 9) × 11111 = 6666600.

Where did this formula come from?

At each decimal place the expected digit value is $$5$$. Since there are $$5!=120$$ such numbers the sum of all the numbers is $$120\cdot 5\cdot 11111=6\,666\,600$$.

Note that if the digits in the same positions of the summands are swapped, the sum does not change: $$\color{red}1\color{blue}3579+\color{green}3\color{brown}1579=\color{red}1\color{brown}1579+\color{green}3\color{blue}3579.$$ Hence, the required sum is: $$\begin{array}{c|c|c} &13579&&11111\\ \hline &\vdots&&\vdots\\ \hline &19735&&11111\\ \hline &31579&&33333 \\ \hline &\vdots&&\vdots\\ \hline &39751&&33333 \\ \hline &51379&&55555\\ \hline +&\vdots&\Rightarrow &\vdots\\ \hline &59731&&55555\\ \hline\ &71359&&77777\\ \hline &\vdots&&\vdots\\ \hline &79531&&77777\\ \hline &91357&&99999\\ \hline &\vdots&&\vdots\\ \hline &97531&&99999\\ \hline \text{Total}&6,666,600&\Leftarrow&4!(1+3+5+7+9)\cdot 11111 \end{array}\\$$

How many numbers have a $$9$$ in the left-most digit position? This must be $$4!$$ because the other four digits can be in any order, and each order gives you one such number.

How many numbers have a $$9$$ in the second digit position? The answer to this is exactly the same.

The same for the third position, and so on.

So all those nines occur $$4!$$ times in the $$10000$$ position (which contributes $$4!\times9\times10000$$ to the sum), $$4!$$ times in the $$1000$$ position (which contributes $$4!\times9\times1000$$ to the sum), etc.

Adding those together, in total the nines contribute $$4!\times9\times11111$$ to the sum.

The same argument is valid for the other digits too, so the sevens contribute $$4!\times7\times11111$$, the fives $$4!\times5\times11111$$ etc.

Adding those together you get $$4!\times(1+3+5+7+9)\times11111$$.

If you want to generalise this to numbers with $$n$$ digits, you need to be able to write the number $$111....111$$ that has $$n$$ digits. These numbers are called repunits, and can be written as $$(10^n-1)/9$$ because $$10^n-1$$ is a number with $$n$$ nines.

So the correct general formula is $$(n-1)!(a_1+...+a_n)(10^n-1)/9$$.