Problem 6 "Difference in sum of squares"
For the first 10 natural numbers, the sum of their squares is
1^2 + 2^2 + ... + 10^2 = 385
For the first 10 natural numbers, the square of their sum is
(1 + 2 + ... + 10)^2 = 3025
The difference between these numbers is 3025-385 = 2640. Similarly, find the difference between the sum of squares and the square of the sum for the first 100 natural numbers.
Python
n = 100
seq = range(1, n+1)
result = sum(seq)**2 - sum(map(lambda x: x**2, seq))
print result
print result == 25164150
result
25164150
True
Recommended Posts