The sum of the numbers from to is .
Hi, is there any general formula for finding the sum of digits from 1 to n (where n can be upto 10^9) .
I know it's got to do with some multiple of 45 (sum of digits from 1 to 9) but can't relate that to the required forumula.
For example, you can find the sum of the digits of all the numbers containing k digits, as follows. There are such numbers (9 possibilities for the first digit, 10 possibilities for each of the remaining k–1 digits). Each of these numbers has k digits, so there are digits altogether. Of these, will be zeros (each number stands a 1-in-10 chance of having a 0 in each position except the first). That leaves other digits. Each of the nine other digits (1 to 9) is equally likely to occur, so each digit occurs times. The sum of the numbers from 1 to 9 is 45, so the sum of all the digits in all the k-digit numbers is .
If you sum that result for k going from 1 to m, you find that the sum of all the digits in all the numbers from 1 to is .
But if you want the result for a general value of n (not of the form ) then you will have a lot more work to do.