Skip to content

Instantly share code, notes, and snippets.

@atushi
Created July 14, 2013 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atushi/5993380 to your computer and use it in GitHub Desktop.
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…
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