The sum of the squares of the first ten natural numbers is:
The square of the sum of the first ten natural numbers is:
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is
Find the difference between the sum of the sqaures of the first one hundred natural numbers and the square of the sum.
limit = 100
sum_sq = 0
sum = 0
for i = 1 to limit do
sum = sum + i
sum_sq = sum_sq + $i^2$
end for
print( $sum^(2)$ - sum_sq)But this is a Brute force method. The
We know
Sum of
We are looking for a function
Solving this we get:
hence :
limit = 100
sum = limit(limit + 1)/2
sum_sq = (2limit + 1)(limit + 1)limit/6
print sum*sum - sum_sqAnswer : 25164150