in reply to Finding sum of all digits from 1 to 1 million.

use the formul ...
<RB> (n+1)*n/2

Why does this work?
look at this ... 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 is the same as

1 + 10 +
2 + 9 +
3 + 8 +
4 + 7 +
5 + 6
which is the same as
11 + 11 + 11 + 11 + 11
which is 11*5 = (n+1)*n/2 where n = 10
  • Comment on Re: Finding sum of all digits from 1 to 1 million.

Replies are listed 'Best First'.
Re: Re: Finding sum of all digits from 1 to 1 million.
by little (Curate) on Jan 24, 2002 at 16:40 UTC
    Sorry, but 10 is not a gidit , its a number, composed of the digits 1 and 0.
    so your solution should look alike:
    0+9
    1+8
    2+7
    3+6
    4+5
    which is 45
    But anyway, I wouldn't be surprised if another one shows up presenting a "correct" solution of "42" grin

    Have a nice day
    All decision is left to your taste