Created
July 14, 2013 06:23
-
-
Save atushi/5993380 to your computer and use it in GitHub Desktop.
Project Euler . Problem 6 . Sum square difference : The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 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 302…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MAXNUM = 100; | |
var sumA = 0; | |
for (var i=1; i<=MAXNUM; i++) { | |
sumA = sumA + (i*i) | |
} | |
var sumB = 0; | |
for (var i=1; i<=MAXNUM; i++) { | |
sumB = sumB + i | |
} | |
sumB = (sumB * sumB) | |
console.log(sumB - sumA); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment