Skip to content

Commit ad0bde6

Browse files
authored
Update Problem006.js (TheAlgorithms#1537)
1 parent 46362e3 commit ad0bde6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Project-Euler/Problem006.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// https://projecteuler.net/problem=6
22

33
export const squareDifference = (num = 100) => {
4-
let sumOfSquares = 0
5-
let sums = 0
6-
for (let i = 1; i <= num; i++) {
7-
sumOfSquares += i ** 2 // add squares to the sum of squares
8-
sums += i // add number to sum to square later
9-
}
4+
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
5+
let sums = (num*(num+1))/2
6+
107
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
118
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy