Sums of Squares and Cubes

Closed formulas for the squares and the cubes.

The whole numbers

Σr, read "the sum of r from r = 1 to n", means 1 + 2 + 3 + … + n. Its closed formula is Σr = n(n + 1)/2. For n = 4, 1 + 2 + 3 + 4 = 10, and 4 × 5 ÷ 2 = 10.

Write the sum forwards and backwards and add the two lines column by column: 1 + n, 2 + (n − 1), 3 + (n − 2), and so on. Every column adds to n + 1, and there are n columns, so twice the sum is n(n + 1).

1 + 2 + … + 4 = 10n = 4slide

1 + 2 + … + n is a staircase; a second copy turned upside down fills its gaps

Set n = 6 and slide the second staircase in

The staircase 1 + 2 + 3 + 4 and an upside-down copy. Slide the copy in: the two make a 4 by 5 rectangle of 20 blocks, so one staircase is 10.

The squares

Σr² = 1² + 2² + … + n² has its own formula: Σr² = n(n + 1)(2n + 1)/6. For n = 3, 1 + 4 + 9 = 14, and 3 × 4 × 7 ÷ 6 = 84 ÷ 6 = 14. For n = 4, 1 + 4 + 9 + 16 = 30, and 4 × 5 × 9 ÷ 6 = 30.

Induction proves it for every n. At n = 1 both sides are 1, since 1 × 2 × 3 ÷ 6 = 1. Suppose it holds for n, and add the next square, (n + 1)²: n(n + 1)(2n + 1)/6 + (n + 1)² = (n + 1)(n(2n + 1) + 6(n + 1))/6 = (n + 1)(2n² + 7n + 6)/6 = (n + 1)(n + 2)(2n + 3)/6. That is the formula with n + 1 in place of n.

For large n the formula is close to n³/3, the area under y = x² from 0 to n. Multiplied out, Σr² = n³/3 + n²/2 + n/6, so the sum is always a little more than that area.

n

The totals 1, 5, 14, 30, 55, 91 for n = 1 to 6, with the vertical scale squeezed. The gold curve n(n + 1)(2n + 1)/6 passes through every one; the dashed curve n³/3 runs just below them.

The cubes

The cubes add to the square of the plain sum: Σr³ = (n(n + 1)/2)². For n = 3, 1 + 8 + 27 = 36, which is 6², and 1 + 2 + 3 = 6. For n = 4, 1 + 8 + 27 + 64 = 100 = 10².

Here is why. Write Tₙ = n(n + 1)/2 for the nth triangle number. Going from Tₙ₋₁ to Tₙ adds n, so Tₙ − Tₙ₋₁ = n, and the two add to n², since (n − 1)n/2 + n(n + 1)/2 = n². So Tₙ² − Tₙ₋₁² = (Tₙ − Tₙ₋₁)(Tₙ + Tₙ₋₁) = n × n² = n³: each cube is the step from one squared triangle number to the next. For n = 3, 6² − 3² = 36 − 9 = 27.

Adding the steps from the start, 1², 3², 6², 10², … climb by 1, 8, 27, 64, …, so the sum of the first n cubes is the square of the nth triangle number.

Building other sums

A sum splits term by term, and a constant factor comes out in front: Σ(r² + 2r) = Σr² + 2Σr = n(n + 1)(2n + 1)/6 + n(n + 1). Taking out n(n + 1)/6 gives n(n + 1)(2n + 1 + 6)/6 = n(n + 1)(2n + 7)/6. For n = 3 the terms are 3, 8 and 15, which add to 26, and 3 × 4 × 13 ÷ 6 = 26.

In the same way Σr(r + 1) = Σr² + Σr = n(n + 1)(n + 2)/3. For n = 4: 2 + 6 + 12 + 20 = 40, and 4 × 5 × 6 ÷ 3 = 40.

A constant adds n times: Σ1 = n, so Σ3 = 3n, not 3. That is how Σ(2r − 1) = 2Σr − n = n(n + 1) − n = n², the sum of the first n odd numbers.

A sum that does not start at 1 is a difference of two sums from 1. Write S(n) for the sum of the first n squares. The squares from 11² to 20² add to S(20) − S(10): 20 × 21 × 41 ÷ 6 − 10 × 11 × 21 ÷ 6 = 2870 − 385 = 2485.

The usual mistakes

Using Σr for Σr². For n = 4 that gives 10 instead of 30.

Squaring the sum for Σr², or cubing it for Σr³. For n = 3, (Σr)² is 36, not 14, and (Σr)³ is 216, not 36. The cubes add to the square of Σr; the squares do not.

Splitting a sum of products into a product of sums. Σ(r × r) is not Σr × Σr: for n = 3 that is 14 against 36.

Writing Σ3 as 3. Each of the n terms is 3, so the sum is 3n.

Subtracting the wrong sum for a range. The squares from 11 to 20 are S(20) − S(10); S(20) − S(11) leaves out 11².

A stack of square layers

In the application below, layer k of a stack holds k² pipes, so a stack of n layers holds Σr² pipes, and the formula replaces adding the layers one by one.

Worked example: A Pipe Yard's Square Layers: How Many Pipes a Stack Holds and How Tall It May Be

Question A pipe yard stacks pipes in square layers. The top layer is a single pipe, the layer below it is a 2 by 2 square of 4 pipes, and the kth layer from the top is a k by k square of k2 pipes. (a) How many pipes are in a stack of 12 layers? (b) The yard allows at most 1000 pipes in one stack. What is the greatest number of layers allowed, and how many of the 1000 does that stack leave unused?

  1. 1.Count the pipes layer by layer. Layer 1 holds 1 pipe, layer 2 holds 22 = 4, layer 3 holds 32 = 9, and layer k holds k2. A stack of n layers therefore holds ∑k=1n k2 pipes, the sum of the first n square numbers.

    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square
    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square
    Layer k is a k by k square, so it holds k2 pipes.
  2. 2.Use the closed formula rather than adding twelve terms: ∑k=1n k2 = n(n+1)(2n+1)6. With n = 12 the top is 12 × 13 × 25.

    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 144
    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 144
    A stack of 12 layers holds ∑k=112 k2 pipes.
  3. 3.(a) 12 × 13 × 256 = 39006 = 650 pipes. Check by adding the twelve layers one at a time: 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 + 121 + 144 = 650.

    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 650
    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 650
    (a) 12 × 13 × 256 = 650 pipes.
  4. 4.For part (b) the formula is quicker than a table. With n = 13 the stack holds 13 × 14 × 276 = 819 pipes, which is inside the limit. With n = 14 it holds 14 × 15 × 296 = 1015 pipes, which is over it.

    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 65013 layers hold 81914 layers would hold 1015
    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 65013 layers hold 81914 layers would hold 1015
    13 layers hold 819 pipes, and 14 layers would hold 1015, over the limit.
  5. 5.(b) The greatest stack allowed is 13 layers. It holds 819 pipes, so it leaves 1000 − 819 = 181 pipes of the allowance unused. A fourteenth layer would need 142 = 196 more pipes, and only 181 are allowed.

    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 65013 layers hold 81914 layers would hold 10151000 − 819 = 181 pipes unused
    05010015014812layer, counted from the toppipes in that layer144layer k is a k by k square1 + 4 + 9 + · · · + 14412 x 13 x 25, divided by 6, = 65013 layers hold 81914 layers would hold 10151000 − 819 = 181 pipes unused
    (b) 13 layers, leaving 1000 − 819 = 181 of the allowance unused.

Answer: (a) 650 pipes; (b) 13 layers, holding 819 pipes and leaving 181 of the 1000 unused

Common mistakes

  • Reaching for n(n+1)2, the formula for the sum of the first n whole numbers, because it is the one most often met. That adds 1 + 2 + … + 12 = 78, the pipes along one edge of each layer, not the pipes in the layers themselves. The square numbers have a formula of their own, n(n+1)(2n+1)6.
  • Turning the limit into a division, such as 1000 ÷ 12, and rounding the result to a number of layers. The limit is on the total, so the test is whether the whole sum for a given n stays under 1000. Here n = 13 gives 819 and n = 14 gives 1015, so the answer is 13 and no rounding came into it.

More series and convergence problems, worked step by step →

Practice Sums of Squares and Cubes in the app