Sum up numbers from 1 to 100000 after removing zeroes

3.6k Views Asked by At

Ok so i have numbers from 1 to 100000.I need to remove the zeroes from all numbers and sum up numbers from 1 to 100000.So if the number is 405 consider it as 45 , if number if 20039 consider it 239. Is there any mathematical way to solve this, i mean any formula or anything.

3

There are 3 best solutions below

1
On BEST ANSWER

It's slightly more natural to consider the numbers from $1$ to $99999$, since they form complete sets of numbers with a certain number of digits; we can then add $1$ for $100000$ in the end.

There are $\displaystyle\binom5k$ ways to select $k$ of the $5$ digits to be non-zero, and they all lead to the same numbers when the zeros are removed. Every non-zero digit can take the values $1$ through $9$, whose sum is $9(9+1)/2=45$. The digits can be chosen independently, so the total for $k$ non-zero digits is $45$ for a given digit times $9^{k-1}$ options for the remaining digits times $\underbrace{1\ldots1}_k=(10^k-1)/9$ for the sum of the valencies of the digits, for a grand total of

$$ \begin{align} \sum_{k=0}^5\binom5k45\cdot9^{k-1}\frac{10^k-1}9 &= \frac59\left(\sum_{k=0}^5\binom5k90^k-\sum_{k=0}^5\binom5k9^k\right) \\ &= \frac59\left(91^5-10^5\right) \\ &=3466789695\;. \end{align} $$

Add the $1$ for $100000$, and the result coincides with Mark's.

0
On

Given the Mathematica flag, you might consider posting this type of question on mathematica.stackexchange.com. Nonetheless,

deleteZeros[n_] := FromDigits[DeleteCases[IntegerDigits[n], 0]];
Total[deleteZeros /@ Range[100000]]

(* Out: 3466789696 *)
0
On

Look. You may ask how many numbers in 1-100000 end with 5 (the looks like xxxxx5 where $x \in \{0,...9\}$) let it be $a_{15}$ , then how many numbers looks like xxxx5x let it be $a_{25}$ and so on . After that you should add all $a_{ij}$, were $i\in\{1,2,3,4,5\}$ and $j\in\{1,...9\}$.