Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Finding sum of all digits from 1 to 1 million.

by vagnerr (Prior)
on Jan 24, 2002 at 00:17 UTC ( #141011=note: print w/ replies, xml ) Need Help??


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

I think you may be right. I don't think the answer you have is correct. There is actualy a formula to calculate the sum of the numbers from 1-n. It is (n^2)/2 + n/2 which in the case of n=1000000 the answer is 500000500000

---If it doesn't fit use a bigger hammer


Comment on Re: Finding sum of all digits from 1 to 1 million.
Re^2: Finding sum of all digits from 1 to 1 million.
by Anonymous Monk on Jan 30, 2013 at 08:59 UTC
    The formula you need is:- 1/2n (n+1) N is the number. Eg (all numbers from one to ten), ten is number. So 1/2 * 10 =5 * (10+1) =55 Comes from sigma notation.....and i never got any gcses :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://141011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (15)
As of 2015-07-06 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls