 # Sum square difference - Project Euler Solution CodePerfectPlus Updated on ・1 min read

Problem Solving Series(For Interview) (9 Part Series) ### Problem Statement:

The sum of the squares of the first ten natural numbers is,

1^2 + 2^2 + ... + 10^2 = 385


The square of the sum of the first ten natural numbers is,

(1+2+3...+10)^2 = 55^2 = 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.

You can find the original question here -> Project Euler

### Sum square difference - Project Euler Solution in python

def difference(n):
"""
This program will return difference between the square of sum and sum of the square.
"""
sumOfSquare = 0
squareOfSum = 0
for i in range(n+1):
squareOfSum += i
sumOfSquare += i ** 2
return squareOfSum ** 2 - sumOfSquare

if __name__ == "__main__":
print(difference(100))


Share Your Solutions for Sum square difference.

Problem Solving Series(For Interview) (9 Part Series)

Posted on by:

### Discussion   