Sum square difference
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 squares of the first one hundred natural numbers and the square of the sum.
const sumOfSquares = (from = 1, to = 1) => {
let sum = 0
for (let index = from; index <= to; index++) {
const number = index
sum += number ** 2
}
return sum
}
const squareOfSum = (from = 1, to = 1) => {
let sum = 0
for (let index = from; index <= to; index++) {
sum += index
}
return sum ** 2
}
console.log(squareOfSum(1, 100) - sumOfSquares(1, 100))
Related articles
Multiples of 3 or 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.