14,850
Start with the first verse:
"99 bottles of beer on the wall, 99 bottles of beer; take one down, pass it around, 98 bottles of beer on the wall."
There are four numbers mentioned in the verse:
99 99 1 98
The next time around, each of these will decrement by one, except, of course, for the one itself (the same goes for each subsequent verse):
99 99 1 98
98 98 1 97
97 97 1 96
.
.
.
2 2 1 1
1 1 1 0
Here is where a few tricks may prove useful.
First, notice that the sum of the third column is going to be 99 (one for each of the 99 verses), so if that 99 is placed atop the last column, the total is simply three times the sum from 1 to 99 (equivalently, three times the sum from 0 to 99).
That sum is easily found as the sum of sets of pairs:
99 + 0 + 98 + 1 + ... + 50 + 49
where each pair adds up to 99.
There are 50 pairs in the series, and the total we are looking for is three times that sum, so the answer is simply:
99 * 150 = 14850
If you start with n bottles, it is much the same:
n n 1 n-1
n-1 n-1 1 n-2
.
.
.
2 1 1 1
1 1 1 0
Again, there are n rows, so the sum of the column of ones is just n, which appended to the top of the last column yields n + n+1 + ... + 1, and an overall sum of three times that, 3(n + n+1 + ... + 1). The sum of the first n numbers (1 + 2 + ... + n) is n(n+1)/2, so the overall sum for the song involving n bottles is (3n/2)(n+1).
Just to check, for n=99, this formula becomes:
(3(99)/2)(100)
= 3(99)(50)
= 14850
which is what we arrived at previously. |