Skip to content

Instantly share code, notes, and snippets.

@jluismm2311
Created September 14, 2015 16:38
Show Gist options
  • Save jluismm2311/33698929ec7a8d9fffb4 to your computer and use it in GitHub Desktop.
Save jluismm2311/33698929ec7a8d9fffb4 to your computer and use it in GitHub Desktop.
Feynman's squares Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing. Recently, an old farmer found some papers and notes that are believed to have belonged to Feynman. Among notes about mesons and electromagneti…
function countSquares(n){
let value = 0;
for(var i = 1; i<=n; i++){
value += i * i;
}
return value;
}
@QApolo
Copy link

QApolo commented Sep 7, 2018

function countSquares(n) { return (n*(n+1)*((n<<1)+1)/6); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment