Project Euler: Problem 6

https://projecteuler.net/problem=6

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 + ... + 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.


In [38]:
##To test out the example from above. I will copy and paste this into the next one with the numbers we actually want.

sum_squares = [x*x for x in range(1,11)]
x = sum(sum_squares)
print(x)

square_sum = (sum(list(range(1,11))))**2
print(square_sum)


385
3025

In [50]:
sum_squares1 = [x*x for x in range(1,101)]
x = sum(sum_squares1)
print(x)

square_sum1 = (sum(list(range(1,101))))**2
print(square_sum1)


answer = (square_sum1 - x)
answer


338350
25502500
Out[50]:
25164150

In [49]:
# This cell will be used for grading, leave it at the end of the notebook.

In [ ]: