how do u get that?
I got it from 'Concrete Mathematics, A foundation for computer science', by Graham,Knuth,Patashnik.
This is a really cool book that goes in great depths into this stuff. I wish I had taken a class in this to learn it better, but oh well.
Section 2.5 covers several different methods for evaluating this exact sum.
Method 0 : Look it up. This is the method I used in answering your question at first.
Method 1 : Guess the answer, then prove it. Not much more interesting.
Method 2 is clever and nifty, however:
Consider the sum of the *cubes* from 1 to N, which I'll call Cn since I'm too lazy to put in the subscript codes.
Cn = sum(k=1..n, k
3) // note more laziness with notation
I'll also define
Sn = sum(k=1..n, k
2) which is what you want to find.
Also note that sum(k=1..n, k) = (1/2)(n)(n+1), I assume you've already figured that one out.
then...
Cn+1 = Cn + (n+1)
3 = sum(k=1..n+1, k
3)
Next change variables on the sum, to l where l = k-1, and so
Cn + (n+1)
3 = sum(l=0..n, (l+1)
3)
= sum(l=0..n, l
3 + 3*l
2 + 3*l + 1)
= 1 + sum(l=1..n, l
3 + 3*l
2 + 3*l + 1)
= 1 + sum(l=1..n, l
3) + 3 * sum(l=1..n, l
2) + 3 * sum(l=1..n, l) + sum(l=1..n, 1)
= 1 + Cn + 3 * Sn + 3 * (1/2)(n)(n+1) + n
The Cn can be subtracted off both sides of this equation, thus removing it. This is convenient since we didn't actually care about it in the first place.
Rearrange a bit, to solve for Sn which is what you want,
Sn = (1/3)*((n+1)
3 - 1 - (3/2)(n)(n+1) - n)
a little more algebra then beats this into the final form
Sn = (1/6)(n)(n+1)(2n+1)