Problem 6 - Sum Square Difference

sum of squares
Author

Vincent Clemson

Published

January 17, 2026

Modified

February 2, 2026

Train tracks leading to Nine Arches Bridge   Demodara, Ella, Sri Lanka - April 30th, 2025

Train tracks leading to Nine Arches Bridge
Demodara, Ella, Sri Lanka - April 30th, 2025

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

https://projecteuler.net/problem=6

Development

This is a straigtforward calculation. It does not require anything complex.

R

Answer 1

Code
sum_sq <- lapply(1:100, `^`, 2) |> unlist() |> sum()
sq_sum <- sum(1:100)^2
sq_sum - sum_sq
[1] 25164150

Python

Answer 1

Code
x = list(range(1,101))
sum_sq = sum([i**2 for i in x])
sq_sum = sum(x)**2
sq_sum - sum_sq
25164150
Back to top

Reuse

© 2023-2026 Vincent Clemson | This post is licensed under <a href='http://creativecommons.org/licenses/by-nc-sa/4.0/' target='_blank'>CC BY-NC-SA 4.0</a>

Citation

For attribution, please cite this work as:
Clemson, Vincent. 2026. “Problem 6 - Sum Square Difference.” January 17, 2026. https://prncevince.xyz/euler/problem/0006.html.