XP is just a number | |
PerlMonks |
Re: Finding sum of all digits from 1 to 1 million.by rbc (Curate) |
on Jan 24, 2002 at 02:11 UTC ( [id://141042]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|