What is the sum of natural numbers that have $5$ digits or less, and all of the digits are distinct? $1+2+3+\dots+7+8+9+10+12+13+\dots+96+97+98+102+103+104+\dots+985+986+987+1023+1024+1025+\dots+9874+9875+9876+10234+10235+10236+\dots+98763+98764+98765=$
The only thing I can do is to evaluate a (bad) upper bound by evaluating the sum of natural numbers from $1$ to $98765$, that is equal to $98765 \times (98765+1)/2=4,877,311,995$. So the desired answer is less than that.
Any help would be appreciated. Thanks.

Firstly, write all the integers from $0$ to $99999$ with exactly five digits, using leading zeroes if necessary. Now consider all the integers whose digits are distinct when written this way: there are $10\cdot 9\cdot 8\cdot 7\cdot 6=30240$ of these. And their average is $99999/2$ (you can see this by pairing off each such number $n$ with its 'complement' $99999-n$). So their sum is $\frac12(30240\cdot 99999)=1,511,984,880$.
This is close, but we are missing all those numbers which have one leading zero and one non-leading zero, and those which have two or more leading zeroes and at most one non-leading zero. We can categorise these by one of the following patterns ($x$ denotes a non-zero digit):
$x0xx,xx0x,xxx0,xxx,x0x,xx0,xx,x0,x$
For each of these patterns, we can find the sum of all matching integers using the above method:
$x0xx$: $9\cdot 8\cdot 7$ such numbers, with average $5055$
$xx0x$: $9\cdot 8\cdot 7$ such numbers, with average $5505$
$xxx0$: $9\cdot 8\cdot 7$ such numbers, with average $5550$
$xxx$: $9\cdot 8\cdot 7$ such numbers, with average $555$
$x0x$: $9\cdot 8$ such numbers, with average $505$
$xx0$: $9\cdot 8$ such numbers, with average $550$
$xx$: $9\cdot 8$ such numbers, with average $55$
$x0$: $9$ such numbers, with average $50$
$x$: $9$ such numbers, with average $5$
I will leave the arithmetic to you. (I did the arithmetic myself, and checked it against a brute-force count using a computer, so I am confident that this method works correctly.)
