Results 1 to 5 of 5

Math Help - Sum of digits of numbers between 1 to n

  1. #1
    Member
    Joined
    Nov 2010
    Posts
    95

    Sum of digits of numbers between 1 to n

    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.
    Thanks .
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Prove It's Avatar
    Joined
    Aug 2008
    Posts
    10,969
    Thanks
    1010
    The sum of the numbers from \displaystyle 1 to \displaystyle n is \displaystyle \frac{n}{2}(1+n).
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Nov 2010
    Posts
    95
    Thanks but i was interested in sum of digits rather than the sum of numbers
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Opalg's Avatar
    Joined
    Aug 2007
    From
    Leeds, UK
    Posts
    4,041
    Thanks
    7
    Quote Originally Posted by pranay View Post
    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 formula.
    I don't think you are going to find a straightforward formula for this, except for some special cases of n.

    For example, you can find the sum of the digits of all the numbers containing k digits, as follows. There are 9*10^{k-1} such numbers (9 possibilities for the first digit, 10 possibilities for each of the remaining k1 digits). Each of these numbers has k digits, so there are 9*k*10^{k-1} digits altogether. Of these, (k-1)*9*10^{k-2} will be zeros (each number stands a 1-in-10 chance of having a 0 in each position except the first). That leaves 9k*10^{k-1} - (k-1)*9*10^{k-2} other digits. Each of the nine other digits (1 to 9) is equally likely to occur, so each digit occurs k*10^{k-1} - (k-1)*10^{k-2} = (9k+1)*10^{k-2} 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 45*(9k+1)*10^{k-2}.

    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 10^m-1 is \boxed{45*m*10^{m-1}}.

    But if you want the result for a general value of n (not of the form 10^m-1 ) then you will have a lot more work to do.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Nov 2010
    Posts
    95
    Thanks a lot for the great explanation , exaclty what i wanted . Thank you
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: December 5th 2011, 01:04 AM
  2. Combinatorics exercise (numbers, digits...)
    Posted in the Statistics Forum
    Replies: 9
    Last Post: September 23rd 2011, 12:57 AM
  3. Numbers whose decimal digits are 0 and 1
    Posted in the Math Challenge Problems Forum
    Replies: 5
    Last Post: May 10th 2010, 10:37 AM
  4. Sum of digits of page numbers
    Posted in the Algebra Forum
    Replies: 4
    Last Post: April 21st 2009, 05:08 AM
  5. Replies: 2
    Last Post: April 3rd 2007, 12:31 PM

Search Tags


/mathhelpforum @mathhelpforum