The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Another finite sum for which there's a closed form. $$\sum_{i=1}^{n} i^2 = \frac{n (n+1) (2n + 1)}{6}$$
and
$$(\sum_{i=1}^{n} i)^{2} = (\frac{n (n+1)}{2})^{2}$$So we have $(\sum_{i=1}^{n} i)^{2} - \sum_{i=1}^{n} i^2 = (\frac{n (n+1)}{2})^{2} - \frac{n (n+1) (2n + 1)}{6}$
In [2]:
def diff_of_sums(N):
return (0.5*N*(N+1))**2 - N*(N+1)*(2*N+1)/6
print diff_of_sums(100)