# Find the sum of all 4-digit numbers formed by using digits 0, 2, 3, 5 and 8?

Find the sum of all 4-digit numbers formed by using digits 0, 2, 3, 5 and 8.

Finding the total number of number is possible, but how can the sum be found?

• Firstly, are you allowing leading zeros eg. 0002? If you aren't, it might help to solve this simpler problem first. Jul 13, 2015 at 14:28
• "Finding the total number of number is possible." Warm-up: how many numbers are there? This will help you think clearly about the problem. Jul 13, 2015 at 14:29
• Hint: Let $f(n)$ be the sum of all n-digit numbers formed using digits 0, 2, 3, 5 and 8. Can you find a recurrence relation for $f$? Jul 13, 2015 at 14:31
• math.stackexchange.com/questions/4042089/…
– V.G
Feb 27, 2021 at 18:28

If you fix 8 as the last digit, you see that there are $4 \cdot 3 \cdot 2$ ways to complete the number. Thus, 8 appears 24 times as the last digit. By the same logic, if we enumerate all possible numbers using these 5 digits, each number appears 24 times in each of the 4 positions. That is, the digit 8 contributes $(24 \cdot 8 + 240 \cdot 8 + 2400 \cdot 8 + 24000 \cdot 8)$. In total, we have $$(0 + 2 + 3 + 5 + 8)(24 + 240 + 2400 + 24000) = 479952$$ as our total sum.

Update: In case 4-digit numbers cannot start with 0, then we have overcounted. Now we have to subtract the amount by which we overcounted, which is found by answering: "What is the sum of all 3-digit numbers formed by using digits 2,3,5, and 8?" Now if 8 appears as the last digit, then there are 6 ways to complete the number, so 8 contributes $(6\cdot 8 + 60 \cdot 8 + 600 \cdot 8)$. In total, we have $$(2 + 3 + 5 + 8)(6 + 60 + 600) = 11988.$$ Subtracting this from the above gives us 467964.

• It's possible that the 4-digit number should not start with 0. Aug 30, 2013 at 7:27
• I've one doubt as $8\cdot 24$ counts sum when $8$ is in unit place (eg. $2305\boxed{8}$), then $5\cdot 240$ counts sum when $5$ in tens place (eg. $230\boxed{5}8$), is there no over count? Aug 25, 2018 at 4:27
• @mnulb: no, there is no overcount until you do not allow numbers to start with $0$. Another way to see it is that there are $5!$ numbers formed from the five digits. One fifth of them have each digit in a given place, so there are $4!=24$ with each digit in the place. Simultaneously there are $4!$ with each digit in another place. This answer is correct. Dec 15, 2018 at 4:36
Total[FromDigits /@ Select[Flatten[Permutations /@
Subsets[{0, 2, 3, 5, 8}, {4}], 1], First[#] =!= 0 &]]

(* Out: 467964 *)