Update Problem006.js (#1537)

This commit is contained in:
Rahul Bhandari
2023-10-15 20:42:09 +05:30
committed by GitHub
parent 46362e3d47
commit ad0bde6ddb

View File

@ -1,11 +1,8 @@
// https://projecteuler.net/problem=6
export const squareDifference = (num = 100) => {
let sumOfSquares = 0
let sums = 0
for (let i = 1; i <= num; i++) {
sumOfSquares += i ** 2 // add squares to the sum of squares
sums += i // add number to sum to square later
}
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
let sums = (num*(num+1))/2
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
}